How to set up a queue so that all subscribers receive messages - Rabbit MQ

I read RabbitMQ in the action book, insert in chapter 2, but one thing the authors say puzzles me. You set up the exchange and send a message, two subscribers are listening to the queue. When the first message arrives, the first subscriber receives it, and the message is deleted after it is confirmed. When the following messages arrive, he moves on to the next listener in a circular fashion. I thought that if I send a message, I want all subscribers to receive it. Am I mistaken in my understanding?

+4
source share
1 answer

It's simple. If you want all subscribers to receive a copy of the message, create multiple queues with substitution binding.

Assuming you have a topic exchange and you post all messages using a routing key like fred.interesting or fred.boring, then if each subscriber declares a queue with a fred binding key. *, then each queue will receive a copy of each message. The only problem is how to name the queues, although RabbitMQ can generate unique names for you.

If I did this, I would have a supervisor process that starts and controls the message processing processes. The supervisor gives each consumer process a queue name, such as fred0001, fred0002, and keeps track of which names are in the game. Using specified names like this makes it easier to use management tools or recording management and monitoring scripts.

+6
source

Source: https://habr.com/ru/post/1394943/


All Articles