简体   繁体   English

RabbitMQ 消息过期通知

[英]RabbitMQ message expiry Notification

Is there a way we can push messages to RabbitMQ and have an expiry time for it and once it expires, it should provide a notification.有没有一种方法可以将消息推送到 RabbitMQ 并为其设置到期时间,一旦到期,它应该提供通知。 Or Is there a way we can deliver the messages in RabbitMQ after a certain amount of time.或者有什么方法可以在一定时间后在RabbitMQ中传递消息。 For example, I want to push a message in the queue and wants it to get delivered after 10 seconds..and simultaneously next messages.例如,我想在队列中推送一条消息,并希望它在 10 秒后传递......同时下一条消息。

The RabbitMQ Delayed Message Plugin adds a new exchange type to RabbitMQ where messages routed by that exchange can be delayed if the users chooses to do so. RabbitMQ Delayed Message Plugin 向 RabbitMQ 添加了一种新的交换类型,如果用户选择这样做,则可以延迟由该交换路由的消息。

You can use it in a way like described below.您可以按照如下所述的方式使用它。

// ... elided code ...
Map<String, Object> args = new HashMap<String, Object>();
args.put("x-delayed-type", "direct");
channel.exchangeDeclare("my-exchange", "x-delayed-message", true, false, args);
// ... more code ...

Regarding the first part of your question, the routing of messages that have expired due to a per-message TTL is a feature of the RabbitMQ dead letter exchange (DLX) .关于您问题的第一部分,由于每条消息 TTL 已过期的消息路由是RabbitMQ 死信交换 (DLX) 的一个功能。

Regarding a delay, this is not something supported by RabbitMQ out of the box, nor in my opinion should it be a feature of a message broker.关于延迟,这不是 RabbitMQ 开箱即用的支持,在我看来也不应该是消息代理的功能。 I can't imagine a legitimate use case where you would deliberately want to introduce a delay into a message queue.我无法想象一个合法的用例,您会故意在消息队列中引入延迟。 In fact, it is a design goal of any message broker to minimize delay with enqueued messages.事实上,任何消息代理的设计目标都是尽量减少排队消息的延迟。 If you find a delay to be appropriate, then it is also likely that a message queue is not the appropriate means of conveyance.如果您发现延迟是合适的,那么消息队列也可能不是合适的传输方式。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM