For those who use Spring-AMQP
In my case the problem was different. I wanted a dead-letter-exchange to be of type direct. And i set both x-dead-letter-exchange
and x-dead-letter-routing-key
for the queue. Plus i had spring.rabbitmq.listener.simple.default-requeue-rejected=false
in the application.properties
.
Seems everything fine, but while debugging i noticed that my SimpleRabbitListenerContainerFactory
has defaultRequeueRejected
as null. So the reason was that when you declare SimpleRabbitListenerContainerFactory
in your @Configuration
, you create a new "non-default" bean. The default one is created for you behind the scene out of your properties. But your SimpleRabbitListenerContainerFactory
in the @Config
, these properties are not read, you must read it yourself and set in java code.
It happened to me, because i just copy-pasted the config from the Spring-AMQP docs when wanted to configure the concurrency. But you should do everything in one place, either in properties, like
spring.rabbitmq.listener.simple.default-requeue-rejected=false
spring.rabbitmq.listener.simple.concurrency=5
spring.rabbitmq.listener.simple.max-concurrency=10
or completely in java, like
@Bean
public SimpleRabbitListenerContainerFactory rabbitListenerContainerFactory(ConnectionFactory connectionFactory) {
SimpleRabbitListenerContainerFactory factory = new SimpleRabbitListenerContainerFactory();
factory.setConnectionFactory(connectionFactory);
factory.setConcurrentConsumers(5);
factory.setMaxConcurrentConsumers(10);
factory.setDefaultRequeueRejected(false);
return factory;
}
These 2 above are the same.
I would expect that when i use the second (java) option is still picks up properties from the application.properties and then i customize then in java, but it doesn't work like this.
And yes, "copy-paste" is evil :)