Configure RabbitMQ to replace an old pending message with a new one

*爱你&永不变心* 提交于 2020-01-23 10:51:08

问题


Is is possible to configure a RabbitMQ exchange or a queue in such a way that at most one message with a given routing key is pending at any time? If new message arrives, the old one would be dropped and the new one enqueued.

If such option is not available, what would be the best way to implement this at the application level? I.e. when application receives a message how can it check if there any more pending messages?


回答1:


You need to install Last Value Cache and enable it. Your exchange will be type "x-lvc", which inherits from the direct exchange type.

each time you connect to MQ, create a queue and bind to this exchange. It will deliver the most recent message to the queue. It is perfect for making sure you get only the most uptodate message. All other messages sent to this exchange are discarded unless there is a queue connected. So once connected you will continue to receive updates.

here are installation instructions: https://github.com/simonmacmullen/rabbitmq-lvc-plugin

here is a similar question: RabbitMQ messaging - initializing consumer



来源:https://stackoverflow.com/questions/13451401/configure-rabbitmq-to-replace-an-old-pending-message-with-a-new-one

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