This site contains the documentation that is relevant to older WSO2 product versions and offerings.
For the latest WSO2 documentation, visit https://wso2.com/documentation/.

WSO2 EI as a RabbitMQ Message Consumer

This section describes how WSO2 Enterprise Integrator(WSO2 EI) can be configured as a RabbitMQ message consumer.

The following is a sample scenario that demonstrates how WSO2 EI is configured to listen to a rabbitMQ queue, consume messages, and send the messages to an HTTP back­-end service.

Note

To create proxy services, sequences, endpoints, message stores and message processors in WSO2 EI, you can either use the management console or copy the XML configuration to the source view. To access the source view on the WSO2 EI management console, go to Manage -> Service Bus -> Source View.

Prerequisites

Configure the sample

  1. Create a custom proxy service with the following configuration. For more information on creating proxy services, see Working with Proxy Services.

    <?xml version="1.0" encoding="UTF­8"?>
    <proxy xmlns="http://ws.apache.org/ns/synapse" name="AMQPProxy" transports="rabbitmq" statistics="disable" trace="enable" startOnLoad="true">
    <target>
     <inSequence>
       <log level="full"/>
       <property name="OUT_ONLY" value="true"/>
       <property name="FORCE_SC_ACCEPTED" value="true" scope="axis2"/>
        <send>
         <endpoint>
           <address uri="http://localhost:9000/services/SimpleStockQuoteService"/>
         </endpoint>
        </send>
     </inSequence>
    </target>
     <outSequence>
       <drop/>
     </outSequence>
        <parameter name="rabbitmq.queue.name">queue</parameter>
        <parameter name="rabbitmq.exchange.name">exchange</parameter>
        <parameter name="rabbitmq.connection.factory">AMQPConnectionFactory</parameter>
       <description/>
    </proxy>
  2. WSO2 EI comes with a default Axis2 server, which you can use as the back-end service for this sample. To start the Axis2 server, navigate to <EI_HOME>/samples/axis2server, and run axis2Server.sh on Linux or axis2Server.bat on Windows.
  3. Deploy the SimpleStockQuoteService client by navigating to <EI_HOME>/samples/axis2Server/src/SimpleStockQuoteService, and running the ant command on the command prompt or shell script. This will build the sample and deploy the service for you. For more information on sample back-end services, see Deploying sample back-end services.

Now you have a running WSO2 EI instance with a custom proxy service and a back­-end service deployed. Next, we will send a message to the back­-end service through WSO2 EI using a sample client.

Execute the sample client

Run the following client to publish a getquote request to the RabbitMQ server exchange that is running on port 5672.

ConnectionFactoryfactory =new ConnectionFactory();
factory.setHost("localhost");
factory.setUsername("guest");
factory.setPassword("guest");
factory.setPort(5672);
Connectionconnection =factory.newConnection();
Channelchannel =connection.createChannel();
channel.queueDeclare("queue",false,false,false,null);
channel.exchangeDeclare("exchange","direct",true);
channel.queueBind("queue","exchange","route");

//Themessagetobesent
Stringmessage ="<m:placeOrder xmlns:m=\"http://services.samples\">" +
+"<m:order>"
+"<m:price>100</m:price>\n"
+"<m:quantity>20</m:quantity>"
+"<m:symbol>RMQ</m:symbol>"
+"</m:order>"
+"</m:placeOrder>";

//PopulatetheAMQPmessageproperties
AMQP.BasicProperties.Builderbuilder =new AMQP.BasicProperties().builder();
builder.contentType("text/xml");
builder.contentEncoding(contentEncoding);

//Publishthemessagetoexchange
channel.basicPublish("exchange","queue",builder.build(),message.getBytes()); 		

Analyzing the output

The direct exchange is bound to the queue with route­-key queue that is consumed by WSO2 EI's RabbitMQ transport receiver. From there the message will be sent to the AMQPProxy and it will be forwarded to the given http url.

If you analyze the console running the sample Axis2 server, you will see the following message indicating that the server has accepted an order

Accepted order #1 for : 7078 stocks of IBM at $ 73.73786002620719