Versions Compared

Key

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

...

  1. Configure WSO2 EI with Apache ActiveMQ and set up the JMS listener. For instructions, see Configure with ActiveMQ.

    Anchor
    sample
    sample

  2. Create a proxy service with the following configuration.To create a proxy service using Tooling, see Working with Proxy Services via Tooling.

    Code Block
    languagexml
    <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/>
            </outSequence>
           </target>
    </proxy>
    Tip
    titleProxy Service Configuration

    The OUT_ONLY property is set to true to indicate that message exchange is one-way.

    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, WSO2 EI will start listening on a JMS queue with the same name as the proxy service.

    In the sample configuration above, WSO2 EI 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. For details, see below.

  3. To test this you will need an HTTP back-end service. Deploy the SimpleStockQuoteService and start the Axis2 server
  4. Place a message into the ActiveMQ queue by executing the following command from <EI_HOME>/samples/axis2Client folder.

    Code Block
    languagexml
    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"

    WSO2 EI will read the message from the ActiveMQ queue and send it to the back-end service. You will see the following response in the Axis2 Server console:

    Code Block
    languagexml
    Fri Dec 16 10:21:11 GST 2016 samples.services.SimpleStockQuoteService  :: Accepted order #1 for : 7424 stocks of IBM at $ 156.74347214873563

...

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


 

Code Block
languagehtml/xml
<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:9000/services/SimpleStockQuoteService"/>
            </endpoint>
         </send>
      </inSequence>
      <outSequence>
         <send/>
      </outSequence><outSequence/>
   </target>
   <parameter name="transport.jms.ContentType">
      <rules>
         <jmsProperty>contentType</jmsProperty>
         <default>text/xml</default>
      </rules>
   </parameter>
</proxy>

Tip

Note that for two-way JMS scenarios the OUT_ONLY property is not used.

Use the following command from <EI_HOME>/samples/axis2Client folder. Note how the transport.jms.ReplyDestination element is specified.

Code Block
languagexml
ant stockquote -Dsymbol=WSO2 -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&transport.jms.ReplyDestination=ResponseQueue" 

You can view the responses from the back-end service in ResponseQueue by accessing the ActiveMQ management console using the URL http://0.0.0.0:8161/admin and using admin as both the username and password.


...

Code Block
 <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><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>

...