Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

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

    Code Block
    <?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 ESB 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 <ESB_HOME>/samples/axis2server, and run axis2Server.sh on Linux or axis2Server.bat on Windows.
  3. Deploy the SimpleStockQuoteService client by navigating to <ESB_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.

...

Code Block
languagejava
ConnectionFactoryfactory =newConnectionFactorynew ConnectionFactory();
factory.setHost(“localhost”"localhost");
factory.setUsername(“guest”"guest");
factory.setPassword(“guest”"guest");
factory.setPort(5672);
Connectionconnection =factory.newConnection();
Channelchannel =connection.createChannel();
channel.queueDeclare(“queue”"queue",false,false,false,null);
channel.exchangeDeclare(“exchange”"exchange","direct",true);
channel.queueBind(“queue”,“exchange”,“route”"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 =newAMQPnew AMQP.BasicProperties().builder();
builder.contentType("text/xml");
builder.contentEncoding(contentEncoding);

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

Analyzing the output

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

...