title: SpringBoot + Rabbitmq - DLQ queue not working
body: <p>I have setup dlq and dlx, but failed message is not redirecting to dlq.
  I am trying to send message from java app as well as from rabbitmq server to MESSAGES.EXCHANGE, in both case i am getting message but after throwing the exception message should redirect to DLX.MESSAGES.EXCHANGE but it is happening.</p>
  <p>Below is java code  and screen shot of rabbitmq serer. everything looks right to me. could not find any problem in code or in rabbitmq server.</p>
  <p><strong>Queue setup code -</strong></p>
  <pre class="lang-java prettyprint-override"><code>public class DLQAmqpConfiguration {
      public static final String DLX_MESSAGES_EXCHANGE = &quot;DLX.MESSAGES.EXCHANGE&quot;;
      public static final String DLQ_MESSAGES_QUEUE = &quot;DLQ.MESSAGES.QUEUE&quot;;
  
      public static final String MESSAGES_QUEUE = &quot;MESSAGES.QUEUE&quot;;
      public static final String MESSAGES_EXCHANGE = &quot;MESSAGES.EXCHANGE&quot;;
      public static final String ROUTING_KEY_MESSAGES_QUEUE = &quot;ROUTING_KEY_MESSAGES_QUEUE&quot;;
  
      @Bean
      Queue messagesQueue() {
          return QueueBuilder.durable(MESSAGES_QUEUE)
                  .withArgument(&quot;x-dead-letter-exchange&quot;, DLX_MESSAGES_EXCHANGE)
                  .build();
      }
  
      @Bean
      DirectExchange messagesExchange() {
          return new DirectExchange(MESSAGES_EXCHANGE);
      }
  
      @Bean
      Binding bindingMessages() {
          return BindingBuilder.bind(messagesQueue()).to(messagesExchange()).with(ROUTING_KEY_MESSAGES_QUEUE);
      }
  
      @Bean
      FanoutExchange deadLetterExchange() {
          return new FanoutExchange(DLX_MESSAGES_EXCHANGE);
      }
  
      @Bean
      Queue deadLetterQueue() {
          return QueueBuilder.durable(DLQ_MESSAGES_QUEUE).build();
      }
  
      @Bean
      Binding deadLetterBinding() {
          return BindingBuilder.bind(deadLetterQueue()).to(deadLetterExchange());
      }
  }
  </code></pre>
  <p><strong>Producer -</strong></p>
  <pre class="lang-java prettyprint-override"><code>    this.template.convertAndSend(DLQAmqpConfiguration.MESSAGES_EXCHANGE,
                  DLQAmqpConfiguration.ROUTING_KEY_MESSAGES_QUEUE, message);
  
  </code></pre>
  <p><strong>Cunsumer  -</strong></p>
  <pre class="lang-java prettyprint-override"><code>    @RabbitListener(queues = DLQAmqpConfiguration.MESSAGES_QUEUE)
      public void receiveMessage(Message message) throws BusinessException {
          System.out.println(&quot;Received failed message, re-queueing: &quot; + message.toString());
          System.out.println(&quot;Received failed message, re-queueing: &quot; + message.getMessageProperties().getReceivedRoutingKey());
          throw new BusinessException();
      }
  
      // this code never running 
      @RabbitListener(queues = DLQAmqpConfiguration.DLQ_MESSAGES_QUEUE)
      public void processFailedMessages(Message message) {
          System.out.println(&quot;Received failed message: &quot; + message.toString());
      }
  </code></pre>
  <p><strong>Exchange -</strong>
  <a href="https://i.stack.imgur.com/AkRfj.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/AkRfj.png" alt="enter image description here" /></a></p>
  <p><strong>QUEUE -</strong></p>
  <p><a href="https://i.stack.imgur.com/C271J.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/C271J.png" alt="enter image description here" /></a></p>
  <p><a href="https://i.stack.imgur.com/V2l7Z.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/V2l7Z.png" alt="enter image description here" /></a></p>
  <p><strong>Logs -</strong></p>
  <pre><code>Received failed message, re-queueing: (Body:'[B@55c36bc9(byte[26])' MessageProperties [headers={}, contentLength=0, receivedDeliveryMode=PERSISTENT, redelivered=true, receivedExchange=MESSAGES.EXCHANGE, receivedRoutingKey=ROUTING_KEY_MESSAGES_QUEUE, deliveryTag=5444, consumerTag=amq.ctag-KrxkDPlc_uoqHOx_bbnvnA, consumerQueue=MESSAGES.QUEUE])
  Received failed message, re-queueing: ROUTING_KEY_MESSAGES_QUEUE
  2020-08-27 21:36:33.460  WARN 13192 --- [ntContainer#0-1] s.a.r.l.ConditionalRejectingErrorHandler : Execution of Rabbit message listener failed.
  
  org.springframework.amqp.rabbit.support.ListenerExecutionFailedException: Listener method 'public void com.example.rabbitmq.RabbitmqApplication.receiveMessage(org.springframework.amqp.core.Message) throws com.example.rabbitmq.errorhandler.BusinessException' threw exception
      at org.springframework.amqp.rabbit.listener.adapter.MessagingMessageListenerAdapter.invokeHandler(MessagingMessageListenerAdapter.java:228) ~[spring-rabbit-2.2.10.RELEASE.jar:2.2.10.RELEASE]
      at org.springframework.amqp.rabbit.listener.adapter.MessagingMessageListenerAdapter.invokeHandlerAndProcessResult(MessagingMessageListenerAdapter.java:148) ~[spring-rabbit-2.2.10.RELEASE.jar:2.2.10.RELEASE]
      at org.springframework.amqp.rabbit.listener.adapter.MessagingMessageListenerAdapter.onMessage(MessagingMessageListenerAdapter.java:133) ~[spring-rabbit-2.2.10.RELEASE.jar:2.2.10.RELEASE]
      at org.springframework.amqp.rabbit.listener.AbstractMessageListenerContainer.doInvokeListener(AbstractMessageListenerContainer.java:1591) ~[spring-rabbit-2.2.10.RELEASE.jar:2.2.10.RELEASE]
      at org.springframework.amqp.rabbit.listener.AbstractMessageListenerContainer.actualInvokeListener(AbstractMessageListenerContainer.java:1510) ~[spring-rabbit-2.2.10.RELEASE.jar:2.2.10.RELEASE]
      at org.springframework.amqp.rabbit.listener.AbstractMessageListenerContainer.invokeListener(AbstractMessageListenerContainer.java:1498) ~[spring-rabbit-2.2.10.RELEASE.jar:2.2.10.RELEASE]
      at org.springframework.amqp.rabbit.listener.AbstractMessageListenerContainer.doExecuteListener(AbstractMessageListenerContainer.java:1489) ~[spring-rabbit-2.2.10.RELEASE.jar:2.2.10.RELEASE]
      at org.springframework.amqp.rabbit.listener.AbstractMessageListenerContainer.executeListener(AbstractMessageListenerContainer.java:1433) ~[spring-rabbit-2.2.10.RELEASE.jar:2.2.10.RELEASE]
      at org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer.doReceiveAndExecute(SimpleMessageListenerContainer.java:970) [spring-rabbit-2.2.10.RELEASE.jar:2.2.10.RELEASE]
      at org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer.receiveAndExecute(SimpleMessageListenerContainer.java:916) [spring-rabbit-2.2.10.RELEASE.jar:2.2.10.RELEASE]
      at org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer.access$1600(SimpleMessageListenerContainer.java:83) [spring-rabbit-2.2.10.RELEASE.jar:2.2.10.RELEASE]
      at org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer$AsyncMessageProcessingConsumer.mainLoop(SimpleMessageListenerContainer.java:1291) [spring-rabbit-2.2.10.RELEASE.jar:2.2.10.RELEASE]
      at org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer$AsyncMessageProcessingConsumer.run(SimpleMessageListenerContainer.java:1197) [spring-rabbit-2.2.10.RELEASE.jar:2.2.10.RELEASE]
      at java.lang.Thread.run(Thread.java:748) [na:1.8.0_131]
  Caused by: com.example.rabbitmq.errorhandler.BusinessException: null
  </code></pre>