This documentation is for WSO2 Enterprise Service Bus version 5.0.0. For the latest ESB, view the latest WSO2 Enterprise Integrator documentation.

All docs This doc
||
Skip to end of metadata
Go to start of metadata

This sample demonstrates how one-way message bridging from JMS to HTTP can be done using the inbound JMS endpoint of the ESB. The JMS inbound protocol implementation in the ESB requires an active JMS server instance to receive the messages that will be consumed by the ESB. This sample uses WSO2 Message Broker (WSO2 MB) as the JMS server. If you are using ActiveMQ as your JMS server, see Sample 901.

Prerequisites

  • Download and setup WSO2 MB. Instructions can be found in the section on setting up WSO2 MB

  • Copy the following JAR files from the <MB_HOME>/client-lib folder to the <ESB_HOME>/repository/components/lib folder.
    • andes-client-3.2.19.jar
    • geronimo-jms_1.1_spec-1.1.0.wso2v1.jar
    • org.wso2.securevault-1.0.0-wso2v2.jar
  • Open the jndi.properties file from the <ESB_HOME>/repository/conf/ directory and make a reference to WSO2 MB as specified below (use carbon as the virtual host). Use either queues or topics.

    # register some connection factories
    # connectionfactory.[jndiname] = [ConnectionURL]
    connectionfactory.QueueConnectionFactory = amqp://admin:admin@clientID/carbon?brokerlist='tcp://localhost:5673'
    connectionfactory.TopicConnectionFactory = amqp://admin:admin@clientID/carbon?brokerlist='tcp://localhost:5673'
    # register some queues in JNDI using the form
    # queue.[jndiName] = [physicalName]
    queue.JMSMS=JMSMS
    # register some connection factories
    # connectionfactory.[jndiname] = [ConnectionURL]
    connectionfactory.QueueConnectionFactory = amqp://admin:admin@clientID/carbon?brokerlist='tcp://localhost:5673'
    connectionfactory.TopicConnectionFactory = amqp://admin:admin@clientID/carbon?brokerlist='tcp://localhost:5673'
    # register some topics in JNDI using the form
    # topic.[jndiName] = [physicalName]
    topic.MyTopic=MyTopic
  • Create a new sample file named synapse_sample_908.xml with one of the following configurations and add it to the <ESB_HOME>/repository/samples/ directory. Select the configuration for queues, or topics, based on how you defined the jndi.properties file above.

    <definitions xmlns="http://ws.apache.org/ns/synapse"> 
    	<registry provider="org.wso2.carbon.mediation.registry.WSO2Registry"> 
    <parameter name="cachableDuration">15000</parameter> 
    </registry> 
    <taskManager provider="org.wso2.carbon.mediation.ntask.NTaskTaskManager"> 
    <parameter name="cachableDuration">15000</parameter> 
    </taskManager> 
    <inboundEndpoint xmlns="http://ws.apache.org/ns/synapse" name="jms_inbound_queue" sequence="request" onError="fault" protocol="jms" suspend="false"> 
    <parameters> 
    <parameter name="interval">1000</parameter> 
    <parameter name="transport.jms.Destination">JMSMS</parameter> 
    <parameter name="transport.jms.CacheLevel">3</parameter> 
    <parameter name="transport.jms.ConnectionFactoryJNDIName">QueueConnectionFactory</parameter> 
    <parameter name="sequential">true</parameter> 
    <parameter name="java.naming.factory.initial">org.wso2.andes.jndi.PropertiesFileInitialContextFactory</parameter> 
    <parameter name="java.naming.provider.url">repository/conf/jndi.properties</parameter> 
    <parameter name="transport.jms.SessionAcknowledgement">AUTO_ACKNOWLEDGE</parameter> 
    <parameter name="transport.jms.SessionTransacted">false</parameter> 
    <parameter name="transport.jms.ConnectionFactoryType">queue</parameter> 
    </parameters> 
    </inboundEndpoint> 
    <sequence name="request" onError="fault"> 
    <call> 
    <endpoint> 
    <address format="soap12" uri="http://localhost:9000/services/SimpleStockQuoteService"/> 
    </endpoint> 
    </call> 
    <drop/> 
    </sequence> 
    </definitions>
    <definitions xmlns="http://ws.apache.org/ns/synapse"> 
    <registry provider="org.wso2.carbon.mediation.registry.WSO2Registry"> 
    <parameter name="cachableDuration">15000</parameter> 
    </registry> 
    <taskManager provider="org.wso2.carbon.mediation.ntask.NTaskTaskManager"> 
    <parameter name="cachableDuration">15000</parameter> 
    </taskManager> 
    <inboundEndpoint xmlns="http://ws.apache.org/ns/synapse" name="jms_inbound_topic" sequence="request" onError="fault" protocol="jms" suspend="false"> 
    <parameters> 
    <parameter name="interval">1000</parameter> 
    <parameter name="transport.jms.Destination">MyTopic</parameter> 
    <parameter name="transport.jms.CacheLevel">3</parameter> 
    <parameter name="transport.jms.ConnectionFactoryJNDIName">TopicConnectionFactory</parameter> 
    <parameter name="sequential">true</parameter> 
    <parameter name="java.naming.factory.initial">org.wso2.andes.jndi.PropertiesFileInitialContextFactory</parameter> 
    <parameter name="java.naming.provider.url">repository/conf/jndi.properties</parameter> 
    <parameter name="transport.jms.SessionAcknowledgement">AUTO_ACKNOWLEDGE</parameter> 
    <parameter name="transport.jms.SessionTransacted">false</parameter> 
    <parameter name="transport.jms.ConnectionFactoryType">topic</parameter> 
    </parameters> 
    </inboundEndpoint> 
    <sequence name="request" onError="fault"> 
    <call>
    <endpoint> 
    <address format="soap12" uri="http://localhost:9000/services/SimpleStockQuoteService"/> 
    </endpoint> 
    </call> 
    <drop/> 
    </sequence> 
    </definitions>

Building the sample

Follow the steps given below.

  1. First, start the WSO2 MB server. See the instructions here.
  2. Start the ESB with the sample 908 configuration. For instructions on starting a sample configuration, see Starting the ESB with a sample configuration.
  3. Start the Axis2 server. For instructions, see Starting the Axis2 server.
  4. Deploy the back-end service SimpleStockQuoteService. For instructions on deploying sample back-end services, see Deploying sample back-end services.

Now you have running instances of the ESB, the Message Broker, and you have a back-end service deployed in the Axis2 server. In the next section, we will send a message to the back-end service through the ESB.

Executing the sample

Follow the steps given below.

  1. Open the management console of WSO2 MB, and log in using admin as the username as well as the password. You can see that the 'jmsms' queue is created in the queue list, or that the 'mytopic' topic is created in the topic list. 

  2. Now you can publish the following message to the queue or the topic:

    <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ser="http://services.samples" xmlns:xsd="http://services.samples/xsd">
      <soap:Header/>
      <soap:Body>
         <ser:getQuote>
            <ser:request>
               <xsd:symbol>WSO2</xsd:symbol>
            </ser:request>
         </ser:getQuote>
      </soap:Body>
    </soap:Envelope>
  3. To publish the message to the queue/topic, do the following:

    • For Queues: Click Publish Messages for the jmsms queue, copy the above message to the Message Body field, and click Send Message.

    • For Topics: Click Details of the mytopic topic, copy the above message to the Text Message field, and click Publish.

Analyzing the output

You will see that the JMS endpoint gets the message from the queue or topic and sends it to the stock quote service. You will see the following log in the terminal of the Axis2 server:

Generating quote for : WSO2
  • No labels