【RabbitMQ】延迟队列报错(NO_ROUTE)

文章目录

  • 一、背景
  • 二、原因
  • 三、解决方法
  • 四、参考资料

一、背景

  1. 使用rabbitmq-delayed-message-exchange延迟队列插件
  2. 设置Mandatory=true,消息无法路由。报错:NO_ROUTE

二、原因

  • 官方说明
  • https://github.com/rabbitmq/rabbitmq-delayed-message-exchange
    【RabbitMQ】延迟队列报错(NO_ROUTE)_第1张图片

解读如下:

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设置

三、解决方法

  1. 往延时队列发消息前设置Mandatory=false

四、参考资料

  1. https://github.com/rabbitmq/rabbitmq-delayed-message-exchange
  2. https://github.com/rabbitmq/rabbitmq-delayed-message-exchange/issues/138
  3. https://github.com/rabbitmq/rabbitmq-delayed-message-exchange/issues/7

你可能感兴趣的:(java,java,后端)