Search code examples
rabbitmqmuleamqpmule-component

Mule:Routing messages to dead letter exchanges for AMQP endpoint using Mule


Using AMQP connectors in mule and trying to achieve a specific use case where if message fails business filtering criteria instead of writing it on output queue it should be routed to dead letter. Suggest Best way to achieve this. sample code:

<mule>
<flow> 
<message source>
<message processor1>
<message processor2>
<message processor3>
<message processor4>
<message processor5>
<amqp:outbound-endpoint>
</flow>
</mule>

Best way to achieve functionality that if message fails in any message processor subsequent message processor should not execute and message should be forwarded to dead letter exchange of queue. So let say if it fails in message processor 2 message processor 3,4 and 5 should not execute and message should be routed to dead letter exchange. If message does not fail in any stage it should be written to queue.


Solution

  • The AMQP transport provides a feature for manual message acknowledgement or rejection (documentation). If you reject a message, and the queue is configured to use a DLX, then the message will be routed there by the broker.

    Try configuring the flow with a catch-exception-strategy as suggested by Victor Romero, and use <amqp:reject-message /> to reject the message. Be sure to configure the connector to use ackMode="MANUAL", as well.