16
votes

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.

1
Why do you want to round-robin the messages? if you want to distribute the work then pump it all into one queue and have multiple "log file" consumers reading from that queue...kzhen
Looking to find out the same. which solution did you find for this?YaOg
I solved this using e2e (exchange-to-exchange) bindings. stackoverflow.com/a/39577177/67065Raine

1 Answers

15
votes

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.