1

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
mstrom
  • 1,655
  • 3
  • 26
  • 41

2 Answers2

1

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

Artem Bilan
  • 113,505
  • 11
  • 91
  • 118
0

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

Community
  • 1
  • 1
mstrom
  • 1,655
  • 3
  • 26
  • 41