【问题标题】:rabbitMQ with spring boot amqp connection infinity error when @Sendto fail当@Sendto失败时,rabbitMQ与spring boot amqp连接无限错误
【发布时间】:2021-03-04 08:53:32
【问题描述】:

我正在使用带有 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)
...

我错过了什么吗?如果需要更多信息,请告诉我。

【问题讨论】:

  • 您是否验证过您的交换和队列是否存在?您介意发布您的配置吗?
  • 我的exchange是不存在的,特意看看@SendTo注解能否完全替代我在Listener中的rabbitTemplate.convertAndSend

标签: java spring spring-boot rabbitmq spring-amqp


【解决方案1】:

默认情况下,如果处理的任何部分失败,则将消息重新排队并重新传递(无限期地)。这可以配置为拒绝并且不重新排队。

但是,当发送失败并出现此错误时,通道会被代理关闭,消息会重新排队并重新传递。 Spring 没有机会干预以阻止重新交付。

您需要避免这种情况才能解决此问题。

【讨论】:

  • 如果是这样,我会阻止使用@SendTo 注释,因为这不是我的期望。学到很多谢谢。 ?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2022-08-23
  • 2017-12-31
  • 1970-01-01
  • 2018-07-07
相关资源
最近更新 更多