JMS Synchronous Invocations: Dual Channel HTTP-to-JMS

A JMS synchronous invocation takes place when a JMS producer receives a response to a JMS request produced by it when invoked. The WSO2 Micro Integrator uses an internal JMS correlation ID to correlate the request and the response. See JMSRequest/ReplyExample for more information. JMS synchronous invocations are further explained in the following use case.

When the proxy service named SMSSenderProxy receives an HTTP request, it publishes that request in a JMS queue named SMSStore . Another proxy service named SMSForwardProxy subscribes to messages published in this queue and forwards them to a back-end service named SimpleStockQuoteService . When this back-end service returns an HTTP response, internal ESB logic is used to save that message as a JMS message in a JMS queue named SMSReceiveNotification. The SMSSenderProxy proxy service picks the response from the SMSReceiveNotification queue and delivers it to the client as an HTTP message using the internal mediation logic.

Note that the SMSSenderProxy proxy service is able to pick up the message from the SMSReceiveNotification queue because the transport.jms.ReplyDestination parameter of the SMSSenderProxy proxy service is set to the same SMSReceiveNotification queue.

Info

Correlation between request and response:

Note that the message that is passed to the back-end service contains the JMS message ID. However, the back-end service is required to return the response using the JMS correlation ID. Therefore, the back-end service should be configured to copy the message ID from the request (the value of the JMSMessageID header) to the correlation ID of the response (using the JMSCorrelationID header).

Synapse configurations

Create two proxy services with the JMS publisher configuration and JMS consumer configuration given below and then deploy the proxy service artifacts in the Micro Integrator.

See the instructions on how to build and run this example.

JMS publisher configuration

Shown below is the SMSSenderProxy proxy service.

<proxy xmlns="http://ws.apache.org/ns/synapse"
           name="SMSSenderProxy"
           transports="https,http"
           statistics="disable"
           trace="disable"
           startOnLoad="true">
       <target>
          <inSequence>
             <property name="transport.jms.ContentTypeProperty"
                       value="Content-Type"
                       scope="axis2"/>
          </inSequence>
          <outSequence>
             <property name="TRANSPORT_HEADERS" scope="axis2" action="remove"/>
             <send/>
          </outSequence>
          <endpoint>
             <address uri="jms:/SMSStore?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=SMSReceiveNotificationStore"/>
          </endpoint>
       </target>
       <description/>
</proxy>

Listed below are some of the properties that can be used with the Property mediator used in this proxy service:

Property Description
TRANSPORT_HEADERS

This property is used in the out sequence to make sure that transport headers (which are JMS headers in this example) are removed from the message when it is passed to the back-end client.

It is recommended to set this property because (according to the JMS specification) a property name can contain any character for which the Character.isJavaIdentifierPart Java method returns 'true'. Therefore when there are headers that contain special characters (e.g accept-encoding), some JMS brokers will give errors.

transport.jms.ContentTypeProperty

The JMS transport uses this property in the above configuration to determine the content type of the response message. If this property is not set, the JMS transport treats the incoming message as plain text.

Note: When this property is used, the content type is determined by the out transport. For example, if the proxy service/API is sending a request, the endpoint reference will determine the content type. Also, if the proxy service/API is sending the response back to the client, the configuration of the service/API will determine the content type.

JMS_WAIT_REPLY

This property can be used to specify how long the system should wait for the JMS queue (SMSRecieveNotification queue) to send the response back. You can add this property to the in sequence as shown below.

<property name="JMS_WAIT_REPLY" value="60000" scope="axis2"/>

JMS_TIME_TO_LIVE

This property can be set in the InSequence of the proxy service to specify the maximum time period for which a message can live without being consumed.

<property name="JMS_TIME_TO_LIVE" scope="axis2" value="20000"/>

The endpoint of this proxy service uses the properties listed below to connect the proxy service to the JMS queue in the Message Broker.

Property Value for this use case Description

address uri

jms:/SMSStore

The destination in which the request received by the proxy service is stored. Note that there are two ways to define the URL:
  • Specify the JNDI name of the JMS queue and the connection factory parameters in the connection URL as shown in the above example.
  • 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: jms:/SMSStore?transport.jms.ConnectionFactory=QueueConnectionFactory

java.naming.factory.initial

org.wso2.andes.jndi.PropertiesFileInitialContextFactory

The initial context factory to use.
The value specified here should be the same as that specified in the <MI_HOME>/conf/deployment.toml `parameter.initial_naming_factory` for the JMS transport receiver (Under [[transport.jms.listener]] section).

java.naming.provider.url

conf/jndi.properties

The location of the JNDI service provider.

transport.jms.DestinationType

queue The destination type of the JMS message that will be generated by the proxy service.
transport.jms.ReplyDestination

SMSReceiveNotificationStore

The destination in which the response generated by the back-end service is stored.

JMS consumer configuration

Create a proxy service named SMSForwardProxy with the configuration given below. This proxy service will consume messages from the SMSStore queue of the Message Broker Profile, and forward the messages to the back-end service.

<proxy xmlns="http://ws.apache.org/ns/synapse"
           name="SMSForwardProxy"
           transports="jms"
           statistics="disable"
           trace="disable"
           startOnLoad="true">
       <target>
          <inSequence>
            <header name="Action" value="urn:getQuote"/>
             <send>
                <endpoint>
                   <address uri="http://localhost:9000/services/SimpleStockQuoteService"/>
                </endpoint>
             </send>
          </inSequence>
          <outSequence>
             <send/>
          </outSequence>
       </target>
       <parameter name="transport.jms.ContentType">
          <rules>
             <jmsProperty>contentType</jmsProperty>
             <default>text/xml</default>
          </rules>
       </parameter>
       <parameter name="transport.jms.ConnectionFactory">myQueueConnectionFactory</parameter>
       <parameter name="transport.jms.DestinationType">queue</parameter>
       <parameter name="transport.jms.Destination">SMSStore</parameter>
       <description/>
</proxy>

The transport.jms.ConnectionFactory , transport.jms.DestinationType parameter and the transport.jms.Destination properties parameter map the proxy service to the SMSStore queue.

Build and run

Create the artifacts:

  1. Set up WSO2 Integration Studio.
  2. Create an integration project with an ESB Configs module and an Composite Exporter.
  3. Create the proxy services with the configurations given above.
  4. Deploy the artifacts in your Micro Integrator.

Set up the broker:

  1. Configure a broker with your Micro Integrator instance. Let's use Active MQ for this example.
  2. Start the broker.
  3. Start the Micro Integrator (after starting the broker).

    Warning

    If you are using message processor with Active MQ broker add the following configuration to the startup script before starting the server as shown below, For Linux/Mac OS update micro-integrator.sh and for Windows update micro-integrator.bat with -Dorg.apache.activemq.SERIALIZABLE_PACKAGES="*" system property.

Set up the back-end service:

  1. Download the back-end service.
  2. Extract the downloaded zip file.
  3. Open a terminal, navigate to the axis2Server/bin/ directory inside the extracted folder.
  4. Execute the following command to start the axis2server with the SimpleStockQuote back-end service:

    sh axis2server.sh
    axis2server.bat

To invoke this service, the address URI of this proxy service is defined as http://localhost:9000/services/SimpleStockQuoteService. Send a POST request to the above address URI with the following payload:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ser="http://services.samples" xmlns:xsd="http://services.samples/xsd">
   <soapenv:Header/>
   <soapenv:Body>
      <ser:getQuote>
         <ser:request>
            <xsd:symbol>IBM</xsd:symbol>
         </ser:request>
      </ser:getQuote>
   </soapenv:Body>
</soapenv:Envelope>
Top