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
SMSSenderProxy proxy service picks the response from the
SMSReceiveNotification queue and delivers it to the client as an HTTP message using internal ESB 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
The 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).
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.
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&java.naming.factory.initial=org.wso2.andes.jndi.PropertiesFileInitialContextFactory&java.naming.provider.url=conf/jndi.properties&transport.jms.DestinationType=queue&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:
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
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.
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.
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.
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|
||The destination in which the request received by the proxy service is stored. Note that there are two ways to define the URL:
The initial context factory to use.
||The location of the JNDI service provider.|
||The destination type of the JMS message that will be generated by the proxy service.|
||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> <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>
transport.jms.DestinationType parameter and the
transport.jms.Destination properties parameter map the proxy service to the
SimpleStockQuoteService sample shipped with WSO2 Micro Integrator is used as the back-end service in this example. To invoke this service, the address URI of this proxy service is defined as