Search code examples
javaspringspring-bootrabbitmqspring-amqp

rabbitMQ with spring boot amqp connection infinity error when @Sendto fail


I'm a using rabbitMQ w/ Spring Boot 2.0.3.

Currently I'm using:

    @Bean
    public SimpleRabbitListenerContainerFactory simpleRabbitListenerContainerFactory()
    {
        SimpleRabbitListenerContainerFactory factory = new SimpleRabbitListenerContainerFactory();

        factory.setConnectionFactory(cachingConnectionFactory);
...
        return factory;
    }

When I'm trying rabbitTemplate.convertAndSend(exchange, routingKey, payload) with non-exist exchange,

error is shown once, which is preferable.

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)

However, when I'm using @SendTo with @RabbitListener, e.g.

@RabbitListener(queues = "test_mq_queue")
@SendTo("exchange/routingKey")

if the exchange is not exist, there will be showing error infinity. e.g.

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)
...

Do I missed something? Let me know if more info needs.


Solution

  • By default, if any part of the processing fails, the message is requeued and redelivered (indefinitely). This can be configured to reject and don't requeue.

    However, when the send fails with this error, the channel is closed by the broker and the message is requeued and redelivered. Spring has no opportunity to intervene to prevent the redelivery.

    You need to avoid this condition to resolve this.