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/.

Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

Version 1 Next »

This section describes how to configure WSO2 ESB to listen to a JMS Queue.

 

Diagram 1 : Simple JMS to HTTP proxy service

The following example code shows the configuration of WSO2 ESB to listen to a JMS queue, consume messages, and send them to a HTTP back-end service.    

To create proxy services, sequences, endpoints, message stores, processors etc. in ESB, you can either use the ESB management console or copy the XML configuration to the source view. You can find the source view under menu Manage > Service Bus > Source View in the left navigation pane of the WSO2 ESB management console.

Sample code 1
<proxy xmlns="http://ws.apache.org/ns/synapse" name="JMStoHTTPStockQuoteProxy" transports="jms">
       <target>
           <inSequence>
               <property action="set" name="OUT_ONLY" value="true"/>
           </inSequence>
           <endpoint>
               <address uri="http://localhost:9000/services/SimpleStockQuoteService"/>
           </endpoint>
           <outSequence>
               <send/>
           </outSequence>
       </target>
</proxy>

For instructions to set up an HTTP back-end service, refer to Starting Sample Back-End Services and to configure JMS Listener for Apache ActiveMQ, refer to Setting up the JMS Listener.
 
To place a message into JMS queue, execute following command from <ESB_HOME>/samples/axis2Client folder. 

ant stockquote -Dmode=placeorder -Dtrpurl="jms:/JMStoHTTPStockQuoteProxy?transport.jms.ConnectionFactoryJNDIName=QueueConnectionFactory&java.naming.factory.initial=org.apache.activemq.jndi.ActiveMQInitialContextFactory&java.naming.provider.url=tcp://localhost:61616&transport.jms.ContentTypeProperty=Content-Type&transport.jms.DestinationType=queue"

You can make the proxy service a JMS listener by setting its transport as jms. Once the JMS transport is enabled for a proxy service, ESB will start listening on a JMS queue with the same name as the proxy service. In the sample code above,  ESB listens to a JMS queue named JMStoHTTPStockQuoteProxy. To make the proxy service listen to a different JMS queue, define the transport.jms.Destination parameter with the name of the destination queue.

Two-way HTTP Back-end Call

In addition to one-way invocations, WSO2 ESB proxy service can listen to the queue, pick up a message and do a two-way HTTP call as well. This is done when the client specifies a replyDestination element when placing a request message to a JMS queue. It allows the response to be delivered to the replyDestination queue specified by the client. The scenario is depicted in the diagram below.

We can have a proxy service similar to the following to simulate a two-way invocation. 

 

<proxy xmlns="http://ws.apache.org/ns/synapse"
       name="Proxy1"
       transports="jms"
       startOnLoad="true"
       trace="disable">
   <description/>
   <target> 
      <inSequence>
         <send>
            <endpoint>
               <address uri="http://localhost:9765/services/t/superqa.com/Axis2Service"/>
            </endpoint>
         </send>
      </inSequence>
      <outSequence>
         <send/>
      </outSequence>
   </target>
   <parameter name="transport.jms.ContentType">
      <rules>
         <jmsProperty>contentType</jmsProperty>
         <default>text/xml</default>
      </rules>
   </parameter>
</proxy>

 

Defining Content Type of Incoming JMS Messages

By default, WSO2 ESB considers all messages consumed from a queue as a SOAP message. To consider messages consumed from a queue as a different format, define the transport.jms.ContentType parameter with the respective content type as a proxy service parameter. The sample code below
 
To demonstrate this, we have modified the sample code 1 as follows to connect to MyJMSQueue queue and read messages as POX messages.
 

Sample Code 2
 <proxy xmlns="http://ws.apache.org/ns/synapse" name="JMStoHTTPStockQuoteProxy" transports="jms">
       <target>
           <inSequence>
               <property action="set" name="OUT_ONLY" value="true"/>
               <send>
                   <endpoint>
                       <address uri="http://localhost:9000/services/SimpleStockQuoteService"/>
                   </endpoint>
               </send>
           </inSequence>
           <outSequence>
               <send/>
           </outSequence>
       </target>
       <parameter name="transport.jms.ContentType">
           <rules>
               <jmsProperty>contentType</jmsProperty>
               <default>application/xml</default>
           </rules>
       </parameter>
       <parameter name="transport.jms.Destination">MyJMSQueue</parameter>
   </proxy>
  • No labels