rabbitmq / rabbitmq-stomp

RabbitMQ STOMP plugin
https://www.rabbitmq.com/stomp.html
Other
49 stars 28 forks source link

Two subscriptions using a single durable queue #109

Closed laurentluce closed 7 years ago

laurentluce commented 7 years ago

Messages don't seem to end up on the right subscription when I have two subscriptions using a single durable queue.

Here is my routing configuration:

rabbitmqctl list_bindings:

rabbitmqctl list_consumers:

rabbitmqctl list_queues:

Message 1 with destination topic.a.1 sent. Message received on the right subscription:

MESSAGE
    subscription : sub.ApMOzTQPNUlvwhmj
    destination : /exchange/app/topic.a.1
    message-id : T_sub.ApMOzTQPNUlvwhmj@@session-uqt3ppLSTqUnYXQBPb4-6w@@1
    redelivered : false
    ack : T_sub.ApMOzTQPNUlvwhmj@@session-uqt3ppLSTqUnYXQBPb4-6w@@1

Message 2 with destination topic.a.1 sent. Message received on the wrong subscription:

MESSAGE
    subscription : sub.HNNZbjRINADxFbrp
    destination : /exchange/app/topic.a.1
    message-id : T_sub.HNNZbjRINADxFbrp@@session-uqt3ppLSTqUnYXQBPb4-6w@@2
    redelivered : false
    ack : T_sub.HNNZbjRINADxFbrp@@session-uqt3ppLSTqUnYXQBPb4-6w@@2

Both messages should have been received on the subscription: ApMOzTQPNUlvwhmj since both messages destination match topic.a. and not topic.b.

michaelklishin commented 7 years ago

According to what you posted, both messages have the same destination and two consumers use a single queue.

When two consumers share a queue, a case known as competing consumers, messages are distributed in the round robin manner. See tutorial two.

If you want both subscription to receive a copy, use a topic destination so that each has its own queue.

michaelklishin commented 7 years ago

In other words, message replication happens during the routing stage, not delivery. If you want N consumers to receive something, they must each have their own queue.

laurentluce commented 7 years ago

@michaelklishin I don't want each subscription to receive a copy. Each subscription above uses a different pattern: topic.a.* and topic.b.* I do use the same queue name when i send the STOMP subscribe commands. I was expecting messages to be received based on the subscriptions topic pattern. The message with destination /exchange/app/topic.a.1 should not be received by the subscription with pattern topic.b.* unless I am missing something.

michaelklishin commented 7 years ago

@laurentluce see above. The feature you are asking for is known as consumer selectors. It is not available in RabbitMQ. Message distribution happens at the routing stage. I don't have anything to add to the comments above.

michaelklishin commented 7 years ago

To be more precise, consumer selectors are implemented in the jms-topic-exchange plugin but it is JMS-specific and doesn't fit the semantics of STOMP.

laurentluce commented 7 years ago

@michaelklishin Thanks for clarifying. I understand now that I need to use two queues.