rabbitmqpublish-subscribejms-topic

Rabbit MQ - can a message be persisted until all subscribed consumers received it?


I'm having a little trouble figuring if Rabbit MQ can publish a message to a single queue with multiple subscribers, where the message will not get deleted until all subscribers to that queue have gotten the message.

The closest I can find is https://www.rabbitmq.com/tutorials/amqp-concepts.html, where it states:

AMQP 0-9-1 has a built-in feature called message acknowledgements (sometimes referred to as acks) that consumers use to confirm message delivery and/or processing. If an application crashes (the AMQP broker notices this when the connection is closed), if an acknowledgement for a message was expected but not received by the AMQP broker, the message is re-queued (and possibly immediately delivered to another consumer, if any exists).

Does this mean if the queue has more than one subscriber, it will wait until the message is consumed by all subscribers?


Solution

  • You should use multiple queues bound to the same exchange, using the same binding. Then, when a message matches the binding, it will be delivered to all queues, which presumably each have a consumer.

    If you have multiple consumers on a single queue, RabbitMQ will round-robin deliveries among those consumers (which is not what you want).