Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to setup queue such a way all subscribers get messages - Rabbit MQ

Tags:

rabbitmq

I am reading RabbitMQ in Action book, stil in the chapter 2, but one thing authors says puzzling me. You setup a exchange and send a message, two subscribers are listening to the queue. When the first message comes in, the first subscriber gets it and the message is removed once it is acknowledged. When the next messages arrives it goes to the next listener in round robin way. I thought, if I am sending a message, I want all the subscribers to get it. Is my understanding wrong?

like image 906
Nair Avatar asked Feb 06 '12 03:02

Nair


People also ask

Is it possible that multiple consumers of a RabbitMQ queue get the same message?

RabbitMQ has a plugin for consistent hash exchange. Using that exchange, and one consumer per queue, we can achieve message order with multiple consumers. The hash exchange distributes routing keys among queues, instead of messages among queues. This means all messages with the same routing key will go the same queue.

How do I get all messages from RabbitMQ?

exports = (connection, queue) => { init(connection, queue); return { getMessages: (queueName, cleanQueue) => new Promise((resolve) => { let messages = []; let i = 1; getChannel(). then((ch) => { ch. consume(queueName, (msg) => { messages. push(msg); console.

Can a queue have multiple consumers?

Support for multiple-consumer queues is a Message Queue feature (the JMS specification defines messaging behavior in the case of only one consumer accessing a queue). When multiple consumers access a queue, the load-balancing among them takes into account each consumer's capacity and message processing rate.


1 Answers

This is simple. If you want all subscribers to get a copy of the message, then create multiple queues with a wildcard binding.

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

If I were doing this I would have a supervisor process that starts and monitors the message consumer processes. The supervisor would assign each consumer process a queue name like fred0001, fred0002 and keep track of which names are in play. Using specified names like this makes it easier to use management tools or write management and monitoring scripts.

like image 113
Michael Dillon Avatar answered Oct 13 '22 06:10

Michael Dillon