rabbitmq - 操作 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 '/'
解决方案
最后我意识到这两个应用程序之间的区别在于第一个应用程序是消费者和生产者。如果应用程序只是一个消费者并且不包含生产者定义,那么spring在broker重启期间处理的exchange重声明失败(即使在此操作之前exchange在节点上已经正确注册)。declareExchange=false
在消费者属性中设置解决了这个问题。
推荐阅读
- vba - 编译错误:未定义子或函数(带有 dll 的 Excel-VBA)
- php - PHP file_get_contents 读取本地文件有时会给我空字符串,但应该总是有一些东西
- flutter - 错误 80070002。在检查 DART SDK 版本时
- php - TinyMCE 不使用 codesample 插件设置代码输出样式?
- android - 在 Flutter 中使用 SQFlite 将本地存储的 DB 导出为可读文件
- moviepy - 如何在moviepy中像素化图像?
- arrays - 使用非 UTF-8 编码的字符串作为映射键
- postgresql - 创建表达式不是一成不变的
- reactjs - 具有激活 onClick 的 onClick 的纸张中的停止按钮
- python - 在 Django 中是否有可能在同一个应用程序中拥有 2 种不同类型的用户和他们自己的登录字段?