You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@qpid.apache.org by James Franco <mj...@gmail.com> on 2016/12/01 18:46:36 UTC

Understanding Topics and Queues association with Exchanges

I am trying to wrap my head around the association of topics and queues
with an exchange. Here is my understanding so far (please correct me if I
am wrong). In the end I have a question .

Point 1:
Whenever we create a queue by default it is under the default exchange
amq.direct.We can move this queue to a different direct exchange using the
bind command shown below:

./qpid-config bind NameOfDirectExchange NameOfQueue bindingKey

Now I would like to know more about topics. Whenever we create a topic we
use the command resembling the one below

./qpid-config add exchange topic news

Now the above command is basically creating an exchange of topic type.

My question is how can I create a topic without creating a new exchange  ?
Say if I wanted to create a topic under the default exchange amq.topic?

Is it possible for one exchange to have both topics and queues ? I would
think not because an exchnage can be either Direct , topic , fanout or
headers am I correct ?

Re: Understanding Topics and Queues association with Exchanges

Posted by James Franco <mj...@gmail.com>.
Ok that makes sense thanks for clearing that up

On Thu, Dec 1, 2016 at 11:24 PM, Rob Godfrey <ro...@gmail.com>
wrote:

> On Fri, 2 Dec 2016 at 00:01, James Franco <mj...@gmail.com> wrote:
>
> > yes it is the qpid hello world example . In your statement
> >
> > "The binding used depends on the topic type (which the client determines
> by
> > asking the broker) and the subject (or other details of the address).
> Since
> > no 'subject' is specified by default in hello world, and the exchange
> type
> > is a 'topic' exchange that supports wildcarding, the key used for the
> > binding is '#' which matches anything."address). Since no 'subject' is
> > specified by default in hello world, and the exchange type is a 'topic'
> > exchange that supports wildcarding, the key used for the binding is '#'
> > which matches anything."
> >
> > Does that mean if a listener is listening to a TopicExchange instead of a
> > queue then it is bound to all the queues of the exchange (i.e the
> listener
> > will get whatever goes through the exchange to other queues) ?
> >
>
> By definition a listener (consumer) in AMQP 0.x can only listen (consume)
> from a queue (there is no way to listen to an exchange).
>
> The addressing syntax used by the clients is an attempt to abstract away
> from the implementation details (queues and exchanges) into more common
> notions such as topics. If you subscribe to an address like foo/bar which
> you expect to provide topic like semantics... then what the client will be
> doing under the covers is creating a temporary queue, binding that to the
> exchange foo with the binding key bar and then listening for message
> arrivals into that temporary queue. Similarly subscribing to just amq.topic
> will bind (with a wildcard) a temporary queue which will receive all
> messages sent to the exchange. One thing that is very misleading in all
> this is that there is nothing specifically "topic" like about the topic
> exchange... it would have much better been called the wildcard exchange.
> You can equally well get topic like behavior from any of the other exchange
> types
>
> -- Rob
>

Re: Understanding Topics and Queues association with Exchanges

Posted by Rob Godfrey <ro...@gmail.com>.
On Fri, 2 Dec 2016 at 00:01, James Franco <mj...@gmail.com> wrote:

> yes it is the qpid hello world example . In your statement
>
> "The binding used depends on the topic type (which the client determines by
> asking the broker) and the subject (or other details of the address). Since
> no 'subject' is specified by default in hello world, and the exchange type
> is a 'topic' exchange that supports wildcarding, the key used for the
> binding is '#' which matches anything."address). Since no 'subject' is
> specified by default in hello world, and the exchange type is a 'topic'
> exchange that supports wildcarding, the key used for the binding is '#'
> which matches anything."
>
> Does that mean if a listener is listening to a TopicExchange instead of a
> queue then it is bound to all the queues of the exchange (i.e the listener
> will get whatever goes through the exchange to other queues) ?
>

By definition a listener (consumer) in AMQP 0.x can only listen (consume)
from a queue (there is no way to listen to an exchange).

The addressing syntax used by the clients is an attempt to abstract away
from the implementation details (queues and exchanges) into more common
notions such as topics. If you subscribe to an address like foo/bar which
you expect to provide topic like semantics... then what the client will be
doing under the covers is creating a temporary queue, binding that to the
exchange foo with the binding key bar and then listening for message
arrivals into that temporary queue. Similarly subscribing to just amq.topic
will bind (with a wildcard) a temporary queue which will receive all
messages sent to the exchange. One thing that is very misleading in all
this is that there is nothing specifically "topic" like about the topic
exchange... it would have much better been called the wildcard exchange.
You can equally well get topic like behavior from any of the other exchange
types

-- Rob

Re: Understanding Topics and Queues association with Exchanges

Posted by James Franco <mj...@gmail.com>.
yes it is the qpid hello world example . In your statement

"The binding used depends on the topic type (which the client determines by
asking the broker) and the subject (or other details of the address). Since
no 'subject' is specified by default in hello world, and the exchange type
is a 'topic' exchange that supports wildcarding, the key used for the
binding is '#' which matches anything."address). Since no 'subject' is
specified by default in hello world, and the exchange type is a 'topic'
exchange that supports wildcarding, the key used for the binding is '#'
which matches anything."

Does that mean if a listener is listening to a TopicExchange instead of a
queue then it is bound to all the queues of the exchange (i.e the listener
will get whatever goes through the exchange to other queues) ?

Re: Understanding Topics and Queues association with Exchanges

Posted by Gordon Sim <gs...@redhat.com>.
On 01/12/16 20:18, James Franco wrote:
> Thanks for the reply Gordon , so another question that I had regarding the
> same topic was about the hello world example and how it is functioning ? In
> that example , we have a message producer and a consumer the producer sends
> a message to the default topic exchange amq.topic . Now I am confused with
> the example primarily because of two reasons:
> 1-A message is being sent to a default Topic Exchange however no queue has
> been associated with it ? Dont topic exchanges have topic queues
> 2-What is the routing key of the message being sent ? since there is no
> subject in the message isnt the routing key empty ?

This is the qpid::messaging hello world example?

Assuming so, the qpid messaging api aims to mask some of the protocol 
specifics. So when you create a receiver with 'amq.topic' as the source, 
the library - if using AMQP 0-10 - will first determine whether that 
source is a queue or an exchange. If it is an exchange (as it will be 
for amq.topic) it then creates a temporary queue on the broker and binds 
that to the exchange in question.

This lets you use an exchange name in the way you would use a topic in 
JMS, i.e. for a non-competing consumer pattern.

The binding used depends on the topic type (which the client determines 
by asking the broker) and the subject (or other details of the address). 
Since no 'subject' is specified by default in hello world, and the 
exchange type is a 'topic' exchange that supports wildcarding, the key 
used for the binding is '#' which matches anything.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@qpid.apache.org
For additional commands, e-mail: users-help@qpid.apache.org


Re: Understanding Topics and Queues association with Exchanges

Posted by James Franco <mj...@gmail.com>.
Thanks for the reply Gordon , so another question that I had regarding the
same topic was about the hello world example and how it is functioning ? In
that example , we have a message producer and a consumer the producer sends
a message to the default topic exchange amq.topic . Now I am confused with
the example primarily because of two reasons:
1-A message is being sent to a default Topic Exchange however no queue has
been associated with it ? Dont topic exchanges have topic queues
2-What is the routing key of the message being sent ? since there is no
subject in the message isnt the routing key empty ?

I would appreciate it if you could help me understand that.


On Thu, Dec 1, 2016 at 7:52 PM, Gordon Sim <gs...@redhat.com> wrote:

> On 01/12/16 18:46, James Franco wrote:
>
>> I am trying to wrap my head around the association of topics and queues
>> with an exchange. Here is my understanding so far (please correct me if I
>> am wrong). In the end I have a question .
>>
>> Point 1:
>> Whenever we create a queue by default it is under the default exchange
>> amq.direct.We can move this queue to a different direct exchange using the
>> bind command shown below:
>>
>> ./qpid-config bind NameOfDirectExchange NameOfQueue bindingKey
>>
>> Now I would like to know more about topics. Whenever we create a topic we
>> use the command resembling the one below
>>
>> ./qpid-config add exchange topic news
>>
>> Now the above command is basically creating an exchange of topic type.
>>
>> My question is how can I create a topic without creating a new exchange  ?
>> Say if I wanted to create a topic under the default exchange amq.topic?
>>
>> Is it possible for one exchange to have both topics and queues ? I would
>> think not because an exchnage can be either Direct , topic , fanout or
>> headers am I correct ?
>>
>
> In AMQP 0-10 and earlier, messages are always published to an exchange and
> always consumed from queues.
>
> Exchanges have bindings associated with them. These are just rules on
> which queues the exchange should forward (or route) a given message to.
>
> There are different types of exchange. The exchange type dictates what
> form the binding 'rules' can take. For a fanout exchange, a binding to a
> queue means that all messages to that exchange should go to that queue. For
> a direct exchange, each binding specifies a 'key' that is matched against a
> special property (called a routing key) of the message being routed using
> an exact match; messages whose routing key is exactly the same as the key
> of a binding are routed to the queue that binding is associated with. A
> topic exchange also uses a key in its bindings, but the matching allows for
> wildcards.
>
> The 'topic' exchange type is (in my view) an unfortunate choice of name.
> You can achieve JMS style 'topic' semantics using any of the exchange
> types. The difference is whether you need wildcard matching or not.
>
> A queue can be bound to more than one exchange, and there can be more than
> one binding between a given queue and exchange (providing these bindings
> differ in some way, e.g. have a different key). Binding doesn't move a
> queue in any way.
>
> The 'default exchange' is really just a way to give the illusion of being
> able to send direct to a queue. The bindings of the default exchange are
> guaranteed to route a message whose routing key is the queue name to that
> queue (and only that queue).
>
> Hope this helps a little. There are some better explanations of the
> concepts available [1][2][3]. Note though that these concepts are specific
> to pre 1.0 versions of the AMQP protocol.
>
> [1] http://qpid.apache.org/releases/qpid-java-6.1.0/java-broker/
> book/Java-Broker-Concepts-Exchanges.html
> [2] https://www.rabbitmq.com/tutorials/amqp-concepts.html
> [3] https://access.redhat.com/documentation/en-US/Red_Hat_Enterp
> rise_MRG/1.1/html/Messaging_User_Guide/chap-Messaging_
> User_Guide-Exchanges.html
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@qpid.apache.org
> For additional commands, e-mail: users-help@qpid.apache.org
>
>

Re: Understanding Topics and Queues association with Exchanges

Posted by Gordon Sim <gs...@redhat.com>.
On 01/12/16 18:46, James Franco wrote:
> I am trying to wrap my head around the association of topics and queues
> with an exchange. Here is my understanding so far (please correct me if I
> am wrong). In the end I have a question .
>
> Point 1:
> Whenever we create a queue by default it is under the default exchange
> amq.direct.We can move this queue to a different direct exchange using the
> bind command shown below:
>
> ./qpid-config bind NameOfDirectExchange NameOfQueue bindingKey
>
> Now I would like to know more about topics. Whenever we create a topic we
> use the command resembling the one below
>
> ./qpid-config add exchange topic news
>
> Now the above command is basically creating an exchange of topic type.
>
> My question is how can I create a topic without creating a new exchange  ?
> Say if I wanted to create a topic under the default exchange amq.topic?
>
> Is it possible for one exchange to have both topics and queues ? I would
> think not because an exchnage can be either Direct , topic , fanout or
> headers am I correct ?

In AMQP 0-10 and earlier, messages are always published to an exchange 
and always consumed from queues.

Exchanges have bindings associated with them. These are just rules on 
which queues the exchange should forward (or route) a given message to.

There are different types of exchange. The exchange type dictates what 
form the binding 'rules' can take. For a fanout exchange, a binding to a 
queue means that all messages to that exchange should go to that queue. 
For a direct exchange, each binding specifies a 'key' that is matched 
against a special property (called a routing key) of the message being 
routed using an exact match; messages whose routing key is exactly the 
same as the key of a binding are routed to the queue that binding is 
associated with. A topic exchange also uses a key in its bindings, but 
the matching allows for wildcards.

The 'topic' exchange type is (in my view) an unfortunate choice of name. 
You can achieve JMS style 'topic' semantics using any of the exchange 
types. The difference is whether you need wildcard matching or not.

A queue can be bound to more than one exchange, and there can be more 
than one binding between a given queue and exchange (providing these 
bindings differ in some way, e.g. have a different key). Binding doesn't 
move a queue in any way.

The 'default exchange' is really just a way to give the illusion of 
being able to send direct to a queue. The bindings of the default 
exchange are guaranteed to route a message whose routing key is the 
queue name to that queue (and only that queue).

Hope this helps a little. There are some better explanations of the 
concepts available [1][2][3]. Note though that these concepts are 
specific to pre 1.0 versions of the AMQP protocol.

[1] 
http://qpid.apache.org/releases/qpid-java-6.1.0/java-broker/book/Java-Broker-Concepts-Exchanges.html
[2] https://www.rabbitmq.com/tutorials/amqp-concepts.html
[3] 
https://access.redhat.com/documentation/en-US/Red_Hat_Enterprise_MRG/1.1/html/Messaging_User_Guide/chap-Messaging_User_Guide-Exchanges.html


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@qpid.apache.org
For additional commands, e-mail: users-help@qpid.apache.org