RabbitMQ Branching Exchange Issues

I can create a fan exchange using the Publish / Sign RabbitMQ Java tutorial, and any connected consumer will receive a copy of the message. Instead of declaring the exchange and binding dynamically / programmatically, I would like to create an exchange and binding before connecting all consumers. I did this through the RabbitMQ management console. For some reason, however, my consumers receive messages in a cyclical mode, and not all receiving copies of the message. What am I missing? Here are some code snippets:

Publisher:

channel.basicPublish("public", "", null, rowId.getBytes("UTF-8")); 

Consumer:

 QueueingConsumer consumer = new QueueingConsumer(channel); channel.basicConsume("myqueue", false, consumer); 

... And in the RabbitMQ management console, I created a "public" exchange like "fanout", and I set the binding from this exchange to "myqueue".

I would be grateful for any help!

+6
source share
1 answer

It looks like all your consumers are subscribing to the same line. When multiple consumers subscribe to the same queue, the default behavior of RabbitMQ is to round messages between all subscribers. See the “Circular Schedule” in RabbitMQ Study Guide No. 2: Work Queues .

A branching exchange is designed to ensure that each queue associated with it receives a copy of the message, and not each consumer. If you want each consumer to receive a copy of the message, usually each user should create their own queue and then become attached to the exchange. I'm not sure why you are trying to avoid programmatically creating / binding a queue, but if you know in advance the number of subscribers and create a queue for each of them, you can get the same effect.

+17
source

All Articles