rabbitmq

RabbitMQ multiple consumer subscribe same queue and get same message


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 ?


Solution

  • 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.

    1. A message from the queue is only consumed by one consumer
    2. You can have competing consumers sharing the work load from a queue

    Very high level AMQP flow

    1. The producer publishes a message to an exchange.
    2. The exchange receives the message and routes it to queues.(Based on message attributes, exchange type and bindings)
    3. The consumer handles the message or it stays in the queue until it is consumed.

    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

    https://www.cloudamqp.com/blog/2015-09-03-part4-rabbitmq-for-beginners-exchanges-routing-keys-bindings.html#standard-rabbitmq-message-flow

    enter image description here

    enter image description here