Reputation: 1743
I have what seems to be a correctly configured RabbitMQ queue (shows the dlx argument) and in my Java listener code, I throw a FatalListenerExecutionException
. For some reason, nothing is showing up in the designated dead letter queue after the exception is thrown.
Am I throwing the wrong kind of exception?
Thanks.
Queue instantiation in Spring configuration:
Map arguments = new HashMap();
arguments.put("x-dead-letter-exchange", "dlx.queue");
new Queue("some.queue", true, false, false, arguments);
Listener Container in Spring configuration:
public SimpleMessageListenerContainer
someContainer(){
final SimpleMessageListenerContainer container = new SimpleMessageListenerContainer();
container.setConnectionFactory(connectionFactory);
container.setQueues(createTheQueue());
container.setMessageListener(theListener());
container.setConcurrentConsumers(numberOfConcurrentConsumers);
container.setMaxConcurrentConsumers(maxDefaultConsumers);
container.setDefaultRequeueRejected(false);
return container;
}
Bindings for "some.queue" shown in RabbitMQ console:
Parameters : x-dead-letter-exchange: dlx.queue
Upvotes: 1
Views: 3993
Reputation: 1743
Actually, I just needed to specify the routing key (since it's a direct exchange and not a fanout). I learned that from this question:
RabbitMQ dead letter exchange never getting messages
Upvotes: 0
Reputation: 121560
You must throw AmqpRejectAndDontRequeueException
or there is just enough to setup defaultRequeuRejected="false"
for the listener container.
See the test-case from Spring AMQP: https://github.com/spring-projects/spring-amqp/blob/master/spring-rabbit/src/test/java/org/springframework/amqp/rabbit/core/FixedReplyQueueDeadLetterTests.java
Upvotes: 1