Sample 263: Transport switching - JMS to http/s using JBoss Messaging(JBM)

<definitions xmlns="http://ws.apache.org/ns/synapse" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://ws.apache.org/ns/synapse http://synapse.apache.org/ns/2010/04/configuration/synapse_config.xsd"> <proxy name="StockQuoteProxy" 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> <publishWSDL uri="file:repository/conf/sample/resources/proxy/sample_proxy_1.wsdl"/> <parameter name="transport.jms.ContentType"> <rules> <jmsProperty>contentType</jmsProperty> <default>application/xml</default> </rules> </parameter> </proxy> </definitions>

Objective

Objective: Introduction to switching transports with proxy services. The JMS provider will be JBoss Messaging(JBM).

Pre-requisites

  • Start the Axis2 server and deploy the SimpleStockQuoteService (Refer steps above)
  • Download , install and start JBM server, and configure Synapse to listen on JBM (refer notes below)
  • Start the Synapse configuration numbered 263
    Unix/Linux: sh synapse.sh -sample 263
    Windows: synapse.bat -sample 23
  • We need to configure the required queues in JBM. Add the following entry to JBM jms configuration inside file-config/stand-alone/non-clustered/jbm-jms.xml. Once JBM is installed and started you should get a message as follows:
    <queue name="StockQuoteProxy"> <entry name="StockQuoteProxy"/> </queue>
  • Once you started the JBM server with the above changes you'll be able to see the following on STDOUT
    10:18:02,673 INFO [org.jboss.messaging.core.server.impl.MessagingServerImpl] JBoss Messaging Server version 2.0.0.BETA3 (maggot, 104) started
  • You will now need to configure the Axis2 instance used by Synapse (not the sample Axis2 server) to enable JMS support using the above provider. Refer Axis2 documentation on setting up JMS in detail (http://ws.apache.org/axis2/1_1/jms-transport.html). You will also need to copy the jbm-core-client.jar, jbm-jms-client.jar, jnp-client.jar(these jars are inside client folder ) and jbm-transports.jar, netty.jar(these jars are from lib folder) jars from JBM into the lib directory to allow Synapse to connect to the JBM JMS provider. This was tested with JBM 2.0.0.BETA3

  • You need to add the following configuration for Axis2 JMS transport listener in axis2.xml found at repository/conf/axis2.xml.

    <transportReceiver name="jms" class="org.apache.axis2.transport.jms.JMSListener"> <parameter name="java.naming.factory.initial">org.jnp.interfaces.NamingContextFactory</parameter> <parameter name="java.naming.provider.url">jnp://localhost:1099</parameter> <parameter name="java.naming.factory.url.pkgs">org.jboss.naming:org.jnp.interfaces</parameter> <parameter name="transport.jms.ConnectionFactoryJNDIName">ConnectionFactory</parameter>
  • On the Synapse debug log you will notice that the JMS listener received the request message as:
    [JMSWorker-1] DEBUG ProxyServiceMessageReceiver -Proxy Service StockQuoteProxy received a new message...
  • In this sample, the client sends the request message to the proxy service exposed over JMS in Synsape. Synapse forwards this message to the HTTP EPR of the simple stock quote service hosted on the sample Axis2 server. Note that the operation is out-only and no response is sent back to the client. The transport.jms.ContentType property is necessary to allow the JMS transport to determine the content type of incoming messages. With the given configuration it will first try to read the content type from the 'contentType' message property and fall back to 'application/xml' (i.e. POX) if this property is not set. Note that the JMS client used in this example doesn't send any content type information.

Executing the Client

Once you start the Synapse configuration 250 and request for the WSDL of the proxy service (http://localhost:8280/services/StockQuoteProxy?wsdl) you will notice that its exposed only on the JMS transport. This is because the configuration specified this requirement in the proxy service definition.

ant jmsclient -Djms_type=pox -Djms_dest=StockQuoteProxy -Djms_payload=MSFT -Djava.naming.provider.url=jnp://localhost:1099 -Djava.naming.factory.initial=org.jnp.interfaces.NamingContextFactory -D=java.naming.factory.url.pkgs=org.jboss.naming:org.jnp.interfaces

Now if you examine the console running the sample Axis2 server, you will see a message indicating that the server has accepted an order as follows:

Accepted order for : 16517 stocks of MSFT at $169.14622538721846

Back to Catalog