Reputation: 635
I am considering that can multiple consumer get the "same" message from a "same" queue which they subscribed ?
It's mean that consumer_1 and consumer_2 are both subscribe queue_1, when a single message is publish by publisher, can two of this consumer get that message at the same time ?
If yes, how can I implement it ?
Upvotes: 4
Views: 14464
Reputation: 843
The other answers miss a key element with CloudAMQP which is that during the acknowledgement of Messages, a Consumer can choose to requeue any given Message. Effectively allowing multiple consumers to see it.
The requeued Message continues onto the "next" consumer (in the order that they connected to the Queue).
I would personally recommend multiple Queues however just for speed, however if you explicitly want all consumers to see a specific Message (and remove it when one consumer explicitly acknowledges it), then it can be a good option to prevent duplication of actions.
See this PHP implementation, or otherwise search "requeue" in CloudAMQP docs.
Upvotes: 0
Reputation: 8213
It is not possible. A particular message from a queue cannot be consumed by more than one consumer.
Remember in AMQP, messages are always consumed from queue.
Very high level AMQP flow
You achieve different message exchange patterns in AMQP based on what exchange type and bindings you create step 2. Whether it is point to point, pub sub, multi cast, it will be based on what happens in step 2.
A nice article with nice diagrams
Upvotes: 10
Reputation: 486
This is not possible. A single message can be delivered to one consumer of a queue at a time. However, it is possible to route a single message to multiple queues though a single exchange. Refer to different forms of bindings and exchanges offered by rabbitMQ.
However, note that rabbitmq offers the option of requeuing and nacks.
Upvotes: 3