当@Sendto 失败时,带有 spring 的 rabbitMQ 启动 amqp 连接无限错误
rabbitMQ with spring boot amqp connection infinity error when @Sendto fail
我正在使用带 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
与 @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 没有机会进行干预以阻止重新投递。
您需要避免这种情况才能解决此问题。
我正在使用带 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
与 @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 没有机会进行干预以阻止重新投递。
您需要避免这种情况才能解决此问题。