Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

RabbitMQ and round robin topic exchanges

Tags:

rabbitmq

I'm seeking some advise as to how best configure my rabbitMQ exchanges.

I'm trying to use a topic exchange in a round robin methodology. Each consumer has its own (uniquely) named queue attached to a topic exchange. I would like the exchange to round robin messages to each consumer queue for the "same" topic - lets say *.log for example.

I have tried multiple combinations and only seem to be able to simultaneously deliver messages to the consumer queues which effectively means I'm processing the message twice, once in each consumer.

For clarity I also have a fanout exchange, which I use to "control" the consumers (start, stop etc).this should remain in place in any outcome.

Any guidance on how best to achieve the stated outcome would be great.

like image 788
Marc Teichtahl Avatar asked Feb 07 '13 07:02

Marc Teichtahl


People also ask

Can RabbitMQ have multiple exchanges?

In RabbitMQ, there are four different types of exchanges that route the message differently using different parameters and bindings setups. Clients can create their own exchanges or use the predefined default exchanges which are created when the server starts for the first time.

What is RabbitMQ topic exchange?

Topic exchange is a built-in exchange in RabbitMQ, enabling the use of wildcards in the binding key. In RabbitMQ, messages are published to an exchange and, depending on the type of exchange, the message gets routed to one or more queues. RabbitMQ has some built-in exchanges and some that are enabled via a plugin.

Is RabbitMQ round robin?

By default, RabbitMQ will send each message to the next consumer, in sequence. On average every consumer will get the same number of messages. This way of distributing messages is called round-robin.


1 Answers

Each consumer has its own (uniquely) named queue attached to a topic exchange

The trick is to have every worker/consumer that you want to round-robin between to setup a named queue and all use the same queue instead creating their own.

So you could create a named queue called "log" for all of the "log" workers. You would create a different named queue for say "foo" for all of the "foo" workers. Requests will be delivered round-robin to all consumers looking at the same queue.

like image 128
Carlos Rendon Avatar answered Sep 18 '22 05:09

Carlos Rendon