一、背景
- 使用rabbitmq-delayed-message-exchange延迟队列插件
- 设置Mandatory=true,消息无法路由。报错:NO_ROUTE
二、原因
- 官方说明
- https://github.com/rabbitmq/rabbitmq-delayed-message-exchange

解读如下:
Delayed messages are stored in a Mnesia table (also see Limitations below) with a single disk replica on the current node
延时队列的消息都是存储在磁盘中
The plugin only performs one attempt at publishing each message but since publishing is local, in practice the only issue that may prevent delivery is the lack of queues (or bindings) to route to.
Closely related to the above, the mandatory flag is not supported by this exchange: we cannot be sure that at the future publishing point in time
there is at least one queue we can route to
the original connection is still around to send a basic.return to
延时消息是从磁盘读取消息然后发送(后台任务),发送消息的时候无法保证两点:
- 1、发送时消息路由的队列还存在
- 2、发送时原连接仍然支持回调方法
- 原因:消息写磁盘和从磁盘读取消息发送存在时间差,两个时间点的队列和连接情况可能不同。所以不支持Mandatory设置
三、解决方法
- 往延时队列发消息前设置Mandatory=false
四、参考资料
- https://github.com/rabbitmq/rabbitmq-delayed-message-exchange
- https://github.com/rabbitmq/rabbitmq-delayed-message-exchange/issues/138
- https://github.com/rabbitmq/rabbitmq-delayed-message-exchange/issues/7
本文介绍了在使用RabbitMQ延迟队列插件时遇到的NO_ROUTE错误,深入分析了该问题的原因:由于消息写磁盘和从磁盘读取发送的时间差,导致无法确保队列存在和连接支持。解决方案是设置Mandatory=false,避免在发送到延迟队列前使用Mandatory=true。
2345

被折叠的 条评论
为什么被折叠?



