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

« Previous Version 11 Next »

This section describes how to configure WSO2 ESB to work as a JMS-to-JMS proxy service.

 

Diagram 3 : Simple JMS to JMS proxy service

The following example code shows the configuration of ESB to both listen to a JMS queue and consume messages as well as to send messages to a JMS queue.

Example code 3
<proxy name="StockQuoteProxy" transports="jms">
   <target>
       <inSequence>
           <property action="set" name="OUT_ONLY" value="true"/>
           <send>
               <endpoint>
                  <address uri="jms:/SimpleStockQuoteService?transport.jms.ConnectionFactoryJNDIName=QueueConnectionFactory&amp;                 java.naming.factory.initial=org.apache.activemq.jndi.ActiveMQInitialContextFactory&amp;java.naming.provider.url=tcp://localhost:61616"/>
               </endpoint>
           </send>
       </inSequence>
   </target>
</proxy>

To place a message into a JMS queue, execute following command from <ESB_HOME>/samples/axis2Client directory. 

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"

Generally, JMS is used for one-way, asynchronous message exchange. However you can perform synchronous messaging also with JMS. Described below is how to configure WSO2 ESB for two-way and quad-channel synchronous messaging.

JMS Synchronous Invocations : Dual Channel HTTP-to-JMS


Diagram 4 : Dual-channel JMS synchronous invocations

The following example code shows configuration of WSO2 ESB for dual-channel JMS synchronous invocations.

Example code 4
<proxy name="StockQuoteProxy" transports="http">
      <target>
          <endpoint>
                  <address uri="jms:/SimpleStockQuoteService?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&amp;transport.jms.ReplyDestination=SimpleStockQuoteServiceReply"/>
          </endpoint>
          <inSequence>
              <property action="set" name="transport.jms.ContentTypeProperty" value="Content-Type" scope="axis2"/>
          </inSequence>
          <outSequence>
              <property action="remove" name="TRANSPORT_HEADERS" scope="axis2"/>
              <send/>
          </outSequence>
      <target>
      <publishWSDL uri="file:repository/conf/sample/resources/proxy/sample_proxy_1.wsdl"/>
</proxy>

The message flow of the sample code is as follows:

  1. The ESB proxy service accepts messages via HTTP and places them in SimpleStockQuoteService JMS queue.
  2. The back-end consumes these messages from the queue and places response messages in the SimpleStockQuoteServiceReply queue.
  3. When a reply is available in the SimpleStockQuoteServiceReply queue, the ESB proxy will pick the response message and send it as the response to the client via HTTP connection.

To send a HTTP message to the ESB proxy service, execute following command from <ESB_HOME>/sample/axis2Client directory. 

ant stockquote -Daddurl=http://localhost:8280/services/StockQuoteProxy -Dmode=placeorder -Dsymbol=MSFT

To co-relate request and response JMS messages, the ESB uses a JMS correlation ID internally. For more information, refer to http://www.eaipatterns.com/RequestReplyJmsExample.html. 

Since this is a two-way invocation, the inSequence does not have the configuration <property action="set" name="OUT_ONLY" value="true"/>. 

The response queue name is defined using transport.jms.ReplyDestination parameter in the JMS connection URL.

JMS Synchronous Invocations : Quad Channel JMS-to-JMS

Diagram 5 : Quad-channel JMS synchronous invocations

The following example code shows configuration of WSO2 ESB for quad-channel JMS synchronous invocations.

Example Code 5
<proxy name="QuadJMS" transports="jms">
      <target>
          <inSequence>
              <property action="set" name="transport.jms.ContentTypeProperty" value="Content-Type" scope="axis2"/>
              <send>
                  <endpoint>
                      <address uri="jms:/BEReq?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&amp;transport.jms.ReplyDestination=BERes"/>
                  </endpoint>
              </send>
          </inSequence>
          <outSequence>
              <send/>
          </outSequence>
      <target>
      <parameter name="transport.jms.Destination">ClientReq</parameter>
</proxy>

The message flow of the sample code is as follows:

  1. JMSReplyTo property of JMS message is set to ClientRes. Therefore, the client sends a JMS message to ClientReq queue.
  2. Next, the transport.jms.ReplyDestination value is set to BERes. This enables the ESB proxy to pick messages from ClientReq queue, and send to BEReq queue.
  3. Next, the back-end picks messages from the BEReq queue, processes and places response messages to BERes queue.
  4. Once a response is available in BERes queue, the proxy service picks it and sends back to ClientRes queue.
  5. Finally, the client picks it as the response message.
  • No labels