Skip to content

How to Publish Unacked Messages to Dead Letter Exchange

This sample demonstrates how WSO2 Integrator: MI can ensure guaranteed delivery of messages by using the Dead Letter Exchange (DLX) of RabbitMQ.

As shown below, a proxy service in the WSO2 Integrator: MI consumes messages from the RabbitMQ broker and sends it to the endpoint. If the message delivery fails, the WSO2 Integrator: MI will route the message to the dead letter exchange of RabbitMQ.

Synapse configurations

See the instructions on how to build and run this example.

<?xml version="1.0" encoding="UTF-8"?>
<proxy xmlns="http://ws.apache.org/ns/synapse"
    name="OrdersService"
    startOnLoad="true"
    statistics="disable"
    trace="disable"
    transports="rabbitmq">
   <target>
    <inSequence>
      <log level="custom">
          <property expression="$body" name="Message Received"/>
      </log>
      <call blocking="true">
          <endpoint>
            <http uri-template="http://localhost:8290/orders"/>
          </endpoint>
      </call>
      <log level="custom">
          <property name="Status" value="The message process successfully"/>
      </log>
    </inSequence>
    <faultSequence>
      <log level="custom">
          <property name="Status" value="Could not process the message"/>
      </log>
      <property name="SET_ROLLBACK_ONLY" scope="axis2" value="true"/>
    </faultSequence>
   </target>
   <parameter name="rabbitmq.queue.autodeclare">false</parameter>
   <parameter name="rabbitmq.exchange.name">orders-exchange</parameter>
   <parameter name="rabbitmq.queue.auto.ack">false</parameter>
   <parameter name="rabbitmq.queue.name">orders</parameter>
   <parameter name="rabbitmq.connection.factory">AMQPConnectionFactory</parameter>
   <parameter name="rabbitmq.message.content.type">application/xml</parameter>
</proxy>

Build and run

  1. Make sure you have a RabbitMQ broker instance running.
  2. Create an exchange with the name orders-exchange.
  3. Create another exchange orders-error-exchange with a queue bound to it (orders-error).
  4. Create queue orders (bound by orders-exchange with routing key orders ) and configure a dead letter exchange for it (orders-error-exchange).
  5. Launch Visual Studio Code with the WSO2 Integrator: MI for VS Code extension (MI for VS Code) installed.

    Info

    Follow the Install WSO2 Integrator: MI for VS Code documentation for a complete installation guide.

  6. Create an integration project.

  7. Create the proxy service with the configurations given above.
  8. Enable the RabbitMQ sender and receiver in the Micro-Integrator from the deployment.toml. Refer the configuring RabbitMQ documentation for more information.
  9. Deploy the artifacts in your WSO2 Integrator: MI.
  10. Make the http://localhost:8290/orders endpoint unavailable temporarily.
  11. Publish a message to the orders queue.
  12. You will see that the failed message has been moved to the dead-letter-exchange.