Skip to content

Synchronous messaging with request-reply pattern

This sample demonstrates how you can implement the request-reply messaging scenario (dual-channel scenario) using the RabbitMQ broker and WSO2 Micro Integrator.

As shown below, the OrderRequest proxy service in the Micro Integrator receives an HTTP request, which it publishes to a RabbitMQ queue. This message is consumed and processed by the OrderProcessing proxy service in the Micro Integrator, and the response is sent back to the client over HTTP.

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="OrderRequestService"
    transports="http https"
    startOnLoad="true">
   <description/>
   <target>
    <inSequence>
      <property name="rabbitmq.message.content.type"
                value="Content-Type"
                scope="axis2"/>
      <property name="TRANSPORT_HEADERS" scope="axis2" action="remove"/>
      <send>
          <endpoint>
            <address uri="rabbitmq:/order-request?rabbitmq.server.host.name=localhost&amp;rabbitmq.server.port=5672&amp;rabbitmq.server.user.name=guest&amp;rabbitmq.server.password=guest"/>
          </endpoint>
      </send>
    </inSequence>
   </target>
</proxy>
<?xml version="1.0" encoding="UTF-8"?>
<proxy xmlns="http://ws.apache.org/ns/synapse"
    name="OrderProcessingService"
    transports="rabbitmq"
    startOnLoad="true">
   <description/>
   <target>
    <inSequence>
      <call>
          <endpoint>
            <http uri-template="http://localhost:8280/orders"/>
          </endpoint>
      </call>
      <log level="custom">
          <property name="Info" value="Your order has been placed successfully."/>
      </log>
      <respond/>
    </inSequence>
    <faultSequence>
      <payloadFactory media-type="xml">
          <format>
            <Error>$1</Error>
          </format>
          <args>
            <arg evaluator="xml" expression="get-property('ERROR_MESSAGE')"/>
          </args>
      </payloadFactory>
      <respond/>
    </faultSequence>
   </target>
   <parameter name="rabbitmq.queue.name">order-request</parameter>
   <parameter name="rabbitmq.connection.factory">AMQPConnectionFactory</parameter>
</proxy>

Build and run

  1. Set up WSO2 Integration Studio.
  2. Create an integration project with an ESB Configs module and an Composite Exporter.
  3. Create the proxy service with the configurations given above.
  4. Enable the RabbitMQ sender and receiver in the Micro-Integrator from the deployment.toml. Refer the configuring RabbitMQ documentation for more information.
  5. Deploy the artifacts in your Micro Integrator.
  6. Make sure you have a RabbitMQ broker instance running.
  7. Send a message to the Order Request Proxy Service with the following payload.

    {   "orderId": "1242",
    "orderQty": 43,
    "orderDate": "2020/07/22"
    }
Top