java - 当@Sendto失败时,rabbitMQ与spring boot amqp连接无限错误
问题描述
我是使用带有 Spring Boot 2.0.3 的 rabbitMQ。
目前我正在使用:
@Bean
public SimpleRabbitListenerContainerFactory simpleRabbitListenerContainerFactory()
{
SimpleRabbitListenerContainerFactory factory = new SimpleRabbitListenerContainerFactory();
factory.setConnectionFactory(cachingConnectionFactory);
...
return factory;
}
当我尝试rabbitTemplate.convertAndSend(exchange, routingKey, payload)
不存在的交换时,
错误显示一次,这是可取的。
2021-03-04 16:20:15.746 ERROR CachingConnectionFactory:1302 [AMQP Connection ip:5672] - Channel shutdown: channel error; protocol method: #method<channel.close>(reply-code=404, reply-text=NOT_FOUND - no exchange 'exchange' in vhost 'vhost', class-id=60, method-id=40)
但是,当我使用@SendTo
with 时@RabbitListener
,例如
@RabbitListener(queues = "test_mq_queue")
@SendTo("exchange/routingKey")
如果交换不存在,将显示错误无穷大。例如
2021-03-04 16:45:23.079 ERROR CachingConnectionFactory:1302 [AMQP Connection ip:5672] - Channel shutdown: channel error; protocol method: #method<channel.close>(reply-code=404, reply-text=NOT_FOUND - no exchange 'exchange' in vhost 'vhost', class-id=60, method-id=40)
2021-03-04 16:45:24.100 ERROR CachingConnectionFactory:1302 [AMQP Connection ip:5672] - Channel shutdown: channel error; protocol method: #method<channel.close>(reply-code=404, reply-text=NOT_FOUND - no exchange 'exchange' in vhost 'vhost', class-id=60, method-id=40)
2021-03-04 16:45:25.125 ERROR CachingConnectionFactory:1302 [AMQP Connection ip:5672] - Channel shutdown: channel error; protocol method: #method<channel.close>(reply-code=404, reply-text=NOT_FOUND - no exchange 'exchange' in vhost 'vhost', class-id=60, method-id=40)
2021-03-04 16:45:26.149 ERROR CachingConnectionFactory:1302 [AMQP Connection ip:5672] - Channel shutdown: channel error; protocol method: #method<channel.close>(reply-code=404, reply-text=NOT_FOUND - no exchange 'exchange' in vhost 'vhost', class-id=60, method-id=40)
2021-03-04 16:45:27.181 ERROR CachingConnectionFactory:1302 [AMQP Connection ip:5672] - Channel shutdown: channel error; protocol method: #method<channel.close>(reply-code=404, reply-text=NOT_FOUND - no exchange 'exchange' in vhost 'vhost', class-id=60, method-id=40)
...
我错过了什么吗?如果需要更多信息,请告诉我。
解决方案
默认情况下,如果处理的任何部分失败,则将消息重新排队并重新传递(无限期地)。这可以配置为拒绝并且不重新排队。
但是,当发送失败并出现此错误时,通道会被代理关闭,消息会重新排队并重新传递。Spring 没有机会进行干预以阻止重新交付。
您需要避免这种情况才能解决此问题。
推荐阅读
- javascript - 如何将不同的页面正确加载到我的网站中?
- c# - C#计算器中的switch语句
- c - 是否可以在没有 sprintf 的情况下将 int 转换为 C 中的字符串?
- jquery - 动态元素无法选择 DOM 的其余部分?
- javascript - 带有子数组创建的 Javascript 对象数组
- firebase-realtime-database - 如何利用 UID 查找获取用户详细信息?
- laravel - 尝试将base64 pdf文件存储在本地存储中
- oboe.js - 部分 JSON 的双簧管?
- vala - MSYS2 Vala 没有控制台输出
- php - Php Switch 只返回第一种情况