首页 > 解决方案 > 操作 queue.declare 导致通道异常 not_found: no queue for spring amqp

问题描述

我有两个应用程序使用相同的spring-amqp配置spring-cloud-stream。但是,当其中一个 rabbitmq 集群节点出现故障时,一个应用程序正在重新声明匿名队列,而第二个应用程序失败。我在日志中发现的唯一区别是 amqqueue 日志中的附加布尔值。应用程序启动期间的整个声明就像一个魅力。唯一的问题是注册队列的 rabbitmq 节点何时关闭。

== 工作应用程序 ==

spring: Auto-declaring a non-durable, auto-delete, or exclusive Queue (myQueueName.anonymous.A6dm37UlRsisaftuN8SwkQ) durable:false, auto-delete:true, exclusive:true. It will be redeclared if the broker stops and is restarted while the connection factory is alive, but all messages will be lost.

rabbit: 2019-08-13 00:27:02.636 [debug] <0.1241.0> Supervisor {<0.1241.0>,rabbit_amqqueue_sup} started rabbit_prequeue:start_link({amqqueue,{resource,<<"/">>,queue,<<"myQueueName.anonymous.A6dm37UlRsisaftuN8SwkQ">>},false,...}, declare, <0.1240.0>) at pid <0.1242.0>

== 申请失败 ==

spring: Auto-declaring a non-durable, auto-delete, or exclusive Queue (myQueueName.anonymous.-6He5tcQSB2Bk17EIiay3g) durable:false, auto-delete:true, exclusive:true. It will be redeclared if the broker stops and is restarted while the connection factory is alive, but all messages will be lost.

rabbit: 2019-08-13 00:24:07.097 [debug] <0.2922.0> Supervisor {<0.2922.0>,rabbit_amqqueue_sup} started rabbit_prequeue:start_link({amqqueue,{resource,<<"/">>,queue,<<"myQueueName.anonymous.-6He5tcQSB2Bk17EIiay3g">>},false,true,...}, declare, <0.2921.0>) at pid <0.2923.0>

rabbit: operation queue.declare caused a channel exception not_found: no queue 'myQueueName.anonymous.-6He5tcQSB2Bk17EIiay3g' in vhost '/'

标签: rabbitmqspring-cloud-streamspring-rabbit

解决方案


最后我意识到这两个应用程序之间的区别在于第一个应用程序是消费者和生产者。如果应用程序只是一个消费者并且不包含生产者定义,那么spring在broker重启期间处理的exchange重声明失败(即使在此操作之前exchange在节点上已经正确注册)。declareExchange=false在消费者属性中设置解决了这个问题。


推荐阅读