Reputation: 5807
I have 2 Rabbitmq nodes connected as a cluster (no queue replication), and have 4 workers, all are bound to the same queue "myqueue", now, I manually publish messages to that queue (the publisher can be connected to any of rabbit nodes .. doesn't affect the result).
Now, this happens: Each time I publish a message to that queue, I find the messages delivered to the workers/consumers in a Round-Robin fashion, no matter what to which node the consumers or the publisher are connected, I always get the same result.
I have been told that this is the effect of Rabbitmq's "prefetch_count", but I don't understand how is that, or even i don't know if that's the right answer.
Upvotes: 2
Views: 2139
Reputation: 1
I know this is very late to answer (11 years) :P
But maybe someone might find this useful.
This behaviour is because of the “exclusive” flag value when you register a consumer node. You can find more information about this in rabbitMQ official documentation.
https://www.rabbitmq.com/docs/consumers#single-active-consumer
#1 What happens if you set exclusive as "true" when registering 4 workers to same "myqueue"?
Only the first registered worker will receive message from the exchange even if other 3 workers are registered. Only when the 1st worker dies, the 2nd registered worker will receive the messages. And when 2 dies, 3 will get and so on. At any point of time, only one worker will be used.
#2 What happens if you set exclusive as "false" when registering 4 workers to same "myqueue"?
All 4 workers will receive the messages in round robin fashion.
#3 What if you want all 4 workers to receive all messages simultaneously?
More information here https://www.rabbitmq.com/tutorials/tutorial-three-java
Upvotes: 0
Reputation: 1814
I think rabbitmq is behaving correctly. When workers are listening to queue, rabbitmq delivers message to consumers in round robin fashion.
Ref: http://www.rabbitmq.com/tutorials/tutorial-two-python.html
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. Try this out with three or more workers.
Upvotes: 1