Skip to content

Consuming and Producing JMS Messages

This section describes how to configure WSO2 Micro Integrator to work as a JMS-to-JMS proxy service. In this example, the Micro Integrator listens to a JMS queue, consumes messages, and then sends those messages to another JMS queue. First we need to configure JMS transport in micro integrator.

Configuring the JMS transport

To enable the JMS transport listener and sender, you need to configure JMS Transport respective to the message broker you are using.

Synapse configuration

Given below is the synapse configuration of the proxy service that mediates the above use case. Note that you need to update the JMS connection URL according to your broker as explained below.

<proxy name="StockQuoteProxy" transports="jms">
    <target>
        <inSequence>
            <property action="set" name="OUT_ONLY" value="true"/>
            <send>
                <endpoint>
                    <address uri=""/> <!-- Specify the JMS connection URL here -->
                </endpoint>
            </send>
        </inSequence>
    </target>
</proxy>

The Synapse artifacts used are explained below.

Artifact Type Description
Proxy Service A proxy service is used to receive messages and to define the message flow. In the sample configuration above, the 'transports' property is set to 'jms', which allows the ESB to receive JMS messages. This proxy StockQuoteProxy and sends messages to another queue named SimpleStockQuoteService.
Property Mediator The OUT ONLY property is set to true , which indicates that the message exchange is one-way.
Send Mediator To send a message to a JMS queue, you should define the JMS connection URL as the endpoint address (which should be invoked via the **Send** mediator). There are two ways to specify the endpoint URL:
  • Specify the JNDI name of the JMS queue and the connection factory parameters in the JMS connection URL as shown in the exampe below. Values of connection factory parameters depend on the type of the JMS broker.

    When the broker is ActiveMQ
    jms:/SimpleStockQuoteService?transport.jms.ConnectionFactoryJNDIName=QueueConnectionFactory&java.naming.factory.initial=org.apache.activemq.jndi.ActiveMQInitialContextFactory&java.naming.provider.url=tcp://localhost:61616&transport.jms.DestinationType=queue

    When the broker is WSO2 Message Broker
    jms:/StockQuotesQueue?transport.jms.ConnectionFactoryJNDIName=QueueConnectionFactory&java.naming.factory.initial=org.wso2.andes.jndi.PropertiesFileInitialContextFactory&java.naming.provider.url=conf/jndi.properties&transport.jms.DestinationType=queue

  • If you have already specified the endpoint's connection factory parameters (for the JMS sender configuration) in the deployment.toml file, the connection URL in the proxy service should be as shown below. In this example, the endpoint URL of the proxy service refers the relevant connection factory in the deployment.toml file:

    When the broker is ActiveMQ
    jms:transport.jms.ConnectionFactory=QueueConnectionFactory

    When the broker is WSO2 Message Broker
    jms:/StockQuotesQueue?transport.jms.ConnectionFactory=QueueConnectionFactory

Info

To refer details on JMS transport parameters, you can follow JMS transport parameters used in micro integrator.

Note

Be sure to replace the ' & ' character in the endpoint URL with '&amp;' to avoid the following exception:

com.ctc.wstx.exc.WstxUnexpectedCharException: Unexpected character '=' (code 61); expected a semi-colon after the reference for entity 'java.naming.factory.initial' at [row,col {unknown-source}

Top