首页 新闻 会员 周边

RabbitMQ的一个队列多个消费者消费,如何保证消息不重复消费

0
[已解决问题] 解决于 2017-10-06 16:34

RabbitMQ的一个队列多个消费者消费,会不会出现多个消费者消费了同一条信息?有的话如何避免?

假如没有的话,是RabbitMQ程序控制了这种情况出现吗?

PowerDK的主页 PowerDK | 菜鸟二级 | 园豆:208
提问于:2017-09-29 09:25
< >
分享
最佳答案
0

单mq而言的话你的fanout的确就支持,其实其他两种也支持,只需要在exchange上配下而已。

但这个东西建议是消费者也要做好防备,避免生产者重复投递消息,甚至包括消费者在消费消息时未ack掉消息的后续处理也需要注意。

奖励园豆:5
Daniel Cai | 专家六级 |园豆:10424 | 2017-09-29 18:12

感谢您的回答

PowerDK | 园豆:208 (菜鸟二级) | 2017-10-06 16:33
其他回答(3)
0

刚在stackoverflow找到答案了

you can't, the way you have things set up. RabbitMQ will round-robin the messages to the consumers, but only one consumer will receive the message from the queue. This is by design in RabbitMQ, when you have multiple consumers on a single queue.

If you need all consumers to receive all messages, then you need to change your configuration so that each consumer has it's own queue. Then you need to publish your message through an exchange that will deliver the message to all of the queues for all of the consumers.

The easiest way to do this is with a Fanout exchange type.

PowerDK | 园豆:208 (菜鸟二级) | 2017-09-29 09:51
1

我感觉只会被消费一次啊.他是轮流分发的.一条只给一个订阅者.

不过应该是可以配置的.

吴瑞祥 | 园豆:29449 (高人七级) | 2017-09-29 10:27

是的,轮流分发

支持(0) 反对(0) PowerDK | 园豆:208 (菜鸟二级) | 2017-09-29 17:06
0

work模式

陈惊蛰 | 园豆:150 (初学一级) | 2019-02-22 10:42
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册