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 多电路系统共用电源的串扰问题
  • ¥15 shape_predictor_68_face_landmarks.dat
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料