1
votes

I have small rabbitmq spring boot application:

@Bean
public SimpleRabbitListenerContainerFactory rabbitListenerContainerFactory(ConnectionFactory connectionFactory)
{
    SimpleRabbitListenerContainerFactory factory = new SimpleRabbitListenerContainerFactory();
    factory.setConnectionFactory(connectionFactory);
    factory.setAcknowledgeMode(AcknowledgeMode.AUTO);
    return factory;
}

Simple queue definition:

@Bean
public Queue queue()
{
    return new Queue("queue");
}

And a simple listener which logs the message:

@RabbitHandler
public void process(@Payload Message message)....

I am seeing that the same message is being sent multiple times before the removed from queue.

How can i change this config to ensure the message is sent exactly once.

1

1 Answers

1
votes

If your listener throws an exception the message will be requeued and sent.

It cannot be sent multiple times otherwise - impossible.

Turn on DEBUG logging to watch the message flow.