Announcement Announcement Module
Collapse
No announcement yet.
Topic Exchange Semantics Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Topic Exchange Semantics

    Hi All,

    Now that, with the help of this forum, I've gotten a simple topic exchange working, I could probably just write the code to test this issue. And I'm sure I will soon do so. But I need to make sure of this quickly, so I will raise it here.

    My understanding of topic exchange behavior is essentially that all subscribers to a queue bound to the exchange will receive all messages whose routing key matches the binding key. Here's a scenario:

    Producer sends to the exchange a message with routing key "status.operator.1234". Given two consumers, each accessing queue statusQueue which they've bound to the exchange with binding key "status.#", both consumers will receive the message.

    Another scenario:

    Producer sends two messages to the exchange, one with routing key "status.operator.1234", the other with routing key "status.operator.4567". Assume 3 consumers all having declared queue statusQueue. Two of the consumers bound with binding key "*.operator.1234"; the other with "*.operator.4567". In this case, the first two consumers will receive the message with routing key "status.operator.1234" and the last consumer will get message "status.operator.4567".

    Is this a correct statement of topic exchange behavior?

    If so, a question arises concerning explicit or implicit ACKing of the message, namely, in the last example if the first consumer ACKs the message is it no longer available to the 2nd consumer? Or is ACKing somehow constrained to a particular consumer's queue?

    Also, what is the effect on topic exchange behavior if each consumer uses a different queue name, or is this irrelevant?

    Thanks for your help with this.

    Cordially,

    Paul

  • #2
    Almost; but you have to separate out the components exchange, queue, consumer.

    If more than one queue is bound to the TopicExchange, with appropriate patterns, a message sent to the exchange will be sent to both queues.

    If more than one consumer is listening on a single queue (regardless of its exchange), only one consumer will receive the message - they are competing consumers for messages on that queue.

    So, your first example - only one consumer will receive the message. In order for both consumers to get a copy, each has to have its own queue bound to the topic exchange with a matching pattern.

    The acks are queue-related so your premise about 2 consumers receiving the same message and one ack affecting the other doesn't apply.

    For high-availability, you could consider two or more competing consumers on each queue (in case one dies); then you would have a queue for each set of clustered consumers.

    Comment


    • #3
      If more than one consumer is listening on a single queue (regardless of its exchange), only one consumer will receive the message - they are competing consumers for messages on that queue.

      So, your first example - only one consumer will receive the message. In order for both consumers to get a copy, each has to have its own queue bound to the topic exchange with a matching pattern.
      What does "single" queue mean in this case; is this a matter of the queue name? For example consumer 1 binds a queue named statusQueue1 to the topic exchange with some binding key; consumer 2 binds a queue named statusQueue2 to the topic exchange with the same binding key. In this case both consumers receive all messages whose routing keys match binding keys - yes?

      But if each consumer binds to queue named statusQueue, then they are competing for messages....?

      Thanks.

      -Paul

      Comment


      • #4
        That is correct.

        Comment


        • #5
          Excellent; thanks.

          Comment

          Working...
          X