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 Producer

This section describes how WSO2 Enterprise Integrator(WSO2 EI) can be used to send messages to a RabbitMQ queue.

Following is a sample scenario that demonstrates how WSO2 EI is configured to listen to HTTP requests and publish them to a RabbitMQ server (message exchange).

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 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="AMQPProducerSample" transports="http" statistics="disable" trace="disable" startOnLoad="true">
    <target>
     <inSequence>
        <property name="OUT_ONLY" value="true"/>
        <property name="FORCE_SC_ACCEPTED" value="true" scope="axis2"/>
         <send>
          <endpoint>
           <address uri="rabbitmq:/AMQPProducerSample?rabbitmq.server.host.name=localhost&amp;rabbitmq.server.port=5672&amp;rabbitmq.queue.name=queue&amp;rabbitmq.queue.route.key=route&amp;rabbitmq.exchange.name=exchange"/>
          </endpoint>
        </send>
     </inSequence>
     <outSequence>
            <send/>
     </outSequence>
    </target>
    <description/>
    </proxy> 
  2. Use the following as a RabbitMQ consumer that will consume and display the incoming messages to the RabbitMQ queue.

    ConnectionFactoryfactory = new ConnectionFactory();
    factory.setHost("localhost");
    factory.setUsername("guest");
    factory.setPassword("guest");
    factory.setPort(5672);
     
    Connectionconnection = factory.new Connection();
    Channelchannel = connection.createChannel();
    channel.queueDeclare("queue",false,false,false,null);
    channel.exchangeDeclare("exchange","direct",true);
    channel.queueBind("queue","exchange","route");
     
    //Createtheconsumer
    QueueingConsumerconsumer = new QueueingConsumer(channel);
    channel.basicConsume("queue",true,consumer);
     
    //Startconsumingmessages
    while(true)
     {
     QueueingConsumer.Deliverydelivery = consumer.nextDelivery();
     String message = new String(delivery.getBody());
     }

Execute the sample client

Execute the following command from <EI_HOME>/sample/axis2Client, to send an HTTP message to the WSO2 EI proxy service.

ant stockquote -Daddurl=http://localhost:8280/services/AMQPProducerSample -Dmode=placeorder

Analyzing the output

You will see that the http request is sent to the given proxy service and that it is forwarded to the RabbitMQ server via the RabbitMQ AMQP transport sender. You can view the messages received at the RabbitMQ queue in the RabbitMQ SimpleProducer console.