Search code examples
muleamqpmule-component

Reject and requeue message in Mule ESB AMQP Connector with ackMode MULE_AUTO


My use case is sending mail via SMTP outbound endpoint.

  • When everything is OK, the message is acknowledged,
  • When validation error (malformed email for example), I want to reject the message,
  • When there is a ConnectionException to the SMTP server, I want to wait 1 minute, reject and requeue the message to give it another try.

I use Mule AMQP Connector with ackMode="MULE_AUTO".

  • When flow is correctly processed, Mule automatically acknowledge the message.
  • When an error occurs in a catch exception strategy, message is rejected and sent to dead letter exchange (no requeue).

I tried using rollback exception strategy but that does not seem to work.

Does anyone know if it is possible to reject and requeue the message ?

(Mule ESB CE 3.7.0 - Mule AMQP Transport 3.6.2.20150520)


Solution

  • Yes It is possible.

    You need to use ackMode=Manual

    1) For success scenario : you need to manually acknowledge the message by using <amqp:acknowledge-message /> at the end of the flow or where you feel in your logic message can be acknowledged.

    2) For failure scenario: Validation error etc, when the exception throws it will be caught in catch exception strategy - use <amqp:reject-message /> . It helps in rejecting the message.

    3)For connection exception: In catch exception strategy use <amqp:reject-message requeue="true" /> which will again push the original message back to the same queue. Reference:https://github.com/mulesoft/mule-transport-amqp/blob/master/GUIDE.md#manual-message-acknowledgement-and-rejection

    Both 2nd and 3rd scenarios needs to be handled in exception strategy. So use ChoiceException strategy where in use 2 catch exception strategy defining one for 'validation error' and other with 'connection Exception'. Reference:https://docs.mulesoft.com/mule-user-guide/v/3.7/choice-exception-strategy

    Note: When using Manual ack, irrespective of success/failure scenario need to manually acknowledge or reject message externally. Missing any keep the message present in the queue.