RabbitMQ-发送消息方式Round-Robin

霸气de小男生 提交于 2019-12-05 18:43:37

When a Rabbit queue has multiple consumers, messages received by the queue are served in a round-robin fashion to the consumers. Each message is sent to only one consumer subscribed to the queue. Let’s say you had a queue named seed_bin and consumers Farmer Bob and Farmer Esmeralda subscribed to seed_bin. As messages arrive in seed_bin, the deliveries would look like this:

1 Message_A arrives in the seed_bin queue.
2 RabbitMQ sends Message_A to Farmer Bob.
3 Farmer Bob acknowledges receipt of Message_A.
4 RabbitMQ removes Message_A from the seed_bin queue.
5 Message_B arrives in the seed_bin queue.
6 RabbitMQ sends Message_B to Farmer Esmeralda.
7 Farmer Esmeralda acknowledges receipt of Message_B.
8 RabbitMQ removes Message_B from the seed_bin queue.

摘自<RabbitMQ in Action>

若存在多个consumer,每个consumer的负载可能不同,有些处理的快有些处理的慢RabbitMQ并不管这些,只是简单的以round-robin的方式分配message这可能造成某些consumer积压很多任务处理不完而一些consumer长期处于饥饿状态可以使用prefetch_count=1的basic_qos方法可告知RabbitMQ只有在consumer处理并确认了上一个message后才分配新的message给他否则分给另一个空闲的consumer

 

 

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!