dongluo6343 2018-01-23 23:57
浏览 386

Rabbitmq队列的多个使用者是否有可能获得相同的消息?

I am in charge maintaining a production software written in Golang which uses RabbitMq as its message queue.
Consider the following situation:

  1. A number of goroutines are publishing to a queue name logs.

  2. Another set goroutines read from the queue and write the messages to a MongoDB collection.

  3. Each publisher or consumer has its Own connection, and its own channel respectively, they are working in an infinite loop and never die. (The connections and channels are established when the program starts.)
  4. autoAck, exclusive and noWait are all set to false and prefetch is set to 20 with global set to false for all channels. All queues are durable with autoDelete, exclusive and noWait all set to false.

The basic assumption was that each message in the queue will be delivered to one and only one consumer, so each message would be inserted in the database exactly once.
The problem is that there are duplicate messages in the MongoDB collection.
I would like to know if it is possible that more than one consumer gets the same message causing them to insert duplicates?

  • 写回答

1条回答 默认 最新

  • dqf98772 2018-01-24 07:35
    关注

    The one case I could see with your setup where a message would be processed more than once is if one of the consumers has an issue at some point. The situation would follow such a scenario:

    1. Consumer gets a bunch of messages from the queue
    2. Consumer starts processing a message
    3. Consumer commits the message to mongodb
    4. either due to rabbitmq channel/connection issue, or other type of issue consumer side, the consumer never acknowledges the message
    5. the message as it hasn't been acknowledged is requeued at the top of the queue
    6. same message is processed again, causing the duplication

    Such cases should show some errors in your consumers logs.

    评论

报告相同问题?

悬赏问题

  • ¥15 使用EMD去噪处理RML2016数据集时候的原理
  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大
  • ¥15 Oracle中如何从clob类型截取特定字符串后面的字符
  • ¥15 想通过pywinauto自动电机应用程序按钮,但是找不到应用程序按钮信息
  • ¥15 如何在炒股软件中,爬到我想看的日k线
  • ¥15 seatunnel 怎么配置Elasticsearch
  • ¥15 PSCAD安装问题 ERROR: Visual Studio 2013, 2015, 2017 or 2019 is not found in the system.
  • ¥15 (标签-MATLAB|关键词-多址)
  • ¥15 关于#MATLAB#的问题,如何解决?(相关搜索:信噪比,系统容量)
  • ¥500 52810做蓝牙接受端