配置RabbitMQ将旧的待处理消息替换为新的消息 [英] Configure RabbitMQ to replace an old pending message with a new one

查看:143
本文介绍了配置RabbitMQ将旧的待处理消息替换为新的消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以通过一种方式配置RabbitMQ交换或队列,以使任何时候都最多有一条带有给定路由密钥的消息挂起?如果收到新消息,则旧消息将被丢弃,新消息将进入队列.

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.

如果该选项不可用,那么在应用程序级别实现此目的的最佳方法是什么?IE.当应用程序收到消息时,如何检查是否还有待处理的消息?

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?

推荐答案

您需要安装Last Value Cache并启用它.您的交易所将是"x-lvc"类型,它继承自直接交易所类型.

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

每次连接到MQ时,创建一个队列并绑定到此交换.它将最新消息传递到队列.这是确保您仅收到最新消息的理想选择.除非连接了队列,否则所有其他发送到该交换机的消息都将被丢弃.因此,一旦连接,您将继续收到更新.

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.

以下是安装说明: https://github.com/simonmacmullen/rabbitmq-lvc-plugin

这是一个类似的问题: RabbitMQ消息传递-初始化消费者

here is a similar question: RabbitMQ messaging - initializing consumer

这篇关于配置RabbitMQ将旧的待处理消息替换为新的消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆