dsh77114 2016-06-23 14:02
浏览 79
已采纳

Rabbit MQ消费者如何工作?

I have 2 questions regarding rabbitmq consumers (receivers):

  1. How can I define (statically from the queue) what are the consumers that are registered to a certain queue, so that if one consumer is down the message will still be delivered after that consumer is up again, or is there any other way to achieve this?
  2. How does consumers connects to a queue that is still not created, in rabbitmq tutorials, I can call the consumer before the producer and it will still work, can someone please explain how this works?

Thanks

  • 写回答

1条回答 默认 最新

  • download2014711 2016-06-23 17:00
    关注
    1. To achieve what you want is simple, this is by design in rabbitmq (just be sure that you don't auto-acknowledge). The message remains in the queue until it's acknowledged. So basically the consumer should finish processing the message and then acknowledge it. If the consumer dies during processing, the message is not ACKed and it gets re-queued. Next time the consumer is up it gets that message. Of course if you have multiple instances of the same (for the sake of simplicity) consumers, the one that is up takes the re-queued message. It's nicely explained in the second tutorial on rmq website.

    2. Declaring queue is an idempotent operation, the queue will be created if it doesn't exist already. If the consumer is the first one to create the queue, that's fine, it's actually usually how it works. The publisher actually does not even (need to) know about the queue, it only cares about exchanges and routing keys. It also doesn't care if anyone is listening, it simply publishes the message. The consumer needs to tell to what routing key does it want to bind the queue.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用
  • ¥15 C++ yoloV5改写遇到的问题
  • ¥20 win11修改中文用户名路径
  • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入
  • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计
  • ¥70 PlayWright在Java上连接CDP关联本地Chrome启动失败,貌似是Windows端口转发问题
  • ¥15 帮我写一个c++工程