RabbitMQ - How to Dead-letter / Process Messages in Expired Queues?

末鹿安然 提交于 2020-03-23 09:00:49

问题


I have an a queue that has x-expires set. The issue I am having is that I need to do further processing on the messages that are in the queue IF the queue expires. My initial idea was to set x-dead-letter-exchange on the queue. But, when the queue expires, the messages just vanish without making it to the dead-letter exchange.

How can I dead-letter, or otherwise process, messages that are in a queue that expires?


回答1:


As suggested in the comments, you cannot do this by relying only on the x-expire feature. But a solution that worked in a similar case I had was to:

  1. Use x-message-ttl to make sure messages die if not consumed in a timely manner,
  2. Assign a dead letter exchange to the queue where all those messages will be routed,
  3. Use x-expires to set the queue expiration to a value higher than the TTL of the messages,
  4. (and this is the tricky part) Assuming you have control over your consumers, before the last consumer goes offline, delete the binding to your "dying" queue, potentially through a REST API call - this will prevent new messages from being routed to the queue.

This way the messages that were published before the last consumer died were already processed, existing messages will be dead-lettered before the queue expires, and new messages cannot come into the queue.




回答2:


You need to add a new dead letter queue that is bound to your dead letter exchange with the binding routing key set as the original queue name. In this way all expired messages sent to the dead letter exchange are routed to the dead letter queue.



来源:https://stackoverflow.com/questions/59259227/rabbitmq-how-to-dead-letter-process-messages-in-expired-queues

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