Tuesday, December 15, 2015

In this Post I'll explain you how to Send a message to a ESB proxy service, Store the message in a messaging queue and respond the client with a custom respone.

The message flow is depicted as below.


As per the above diagram, A request is sent to the ESB and ESB will send out the message to ActiveMQ as a OUT_ONLY message, where ESB will not expect a response from ActiveMQ, at the same time the ESB will send a response to the client.

To achieve this first you need to enable JMS transport senders and listeners in the ESB in-order to receive and send JMS messages. You can do this by following this.

After configuring the ESB create the following Proxy service. Now when you send a request to the following proxy it will send store a message in the JMS queue and send a response to the client.

<?xml version="1.0" encoding="UTF-8"?>
<proxy xmlns="http://ws.apache.org/ns/synapse"
       name="TestJMS"
       transports="http,jms"
       statistics="disable"
       trace="disable"
       startOnLoad="true">
   <target>
      <inSequence>
         <property name="OUT_ONLY" value="true" scope="default" type="STRING"/>
         <log>
            <property name="==" value="============== In the In Sequence ================"/>
         </log>
         <call>
            <endpoint>
               <address uri="jms:/TESTQUEUE?transport.jms.ConnectionFactoryJNDIName=QueueConnectionFactory&amp;java.naming.factory.initial=org.apache.activemq.jndi.ActiveMQInitialContextFactory&amp;java.naming.provider.url=tcp://localhost:61616&amp;transport.jms.DestinationType=queue"/>
            </endpoint>
         </call>
         <payloadFactory media-type="xml">
            <format>
               <Response xmlns="">CUSTOM RESPONSE!!!</Response>
            </format>
            <args/>
         </payloadFactory>
         <respond/>
      </inSequence>
      <outSequence>
         <send/>
      </outSequence>
   </target>
   <description/>
</proxy>

In the above proxy please note the OUT_ONLY property which tells the ESB to send the message out and ignore any response.

Hope this post is useful to someone, Feel free to drop a comment if you have any queries. :)
Categories:

1 comment:

  1. can we read specific message from queue through proxy service(wso2 esb)?

    ReplyDelete

Subscribe to RSS Feed Follow me on Twitter!