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 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
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.
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&java.naming.factory.initial=org.apache.activemq.jndi.ActiveMQInitialContextFactory&java.naming.provider.url=tcp://localhost:61616&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.
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> <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>
transport.jms.DestinationType parameter and the
transport.jms.Destination properties parameter map the proxy service to the
Build and run¶
Create the artifacts:
- Set up WSO2 Integration Studio.
- Create an integration project with an ESB Configs module and an Composite Exporter.
- Create the proxy services with the configurations given above.
- Deploy the artifacts in your Micro Integrator.
Set up the broker:
- Configure a broker with your Micro Integrator instance. Let's use Active MQ for this example.
- Start the broker.
Start the Micro Integrator (after starting the broker).
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.shand for Windows update
Set up the back-end service:
- Download the back-end service.
- Extract the downloaded zip file.
- Open a terminal, navigate to the
axis2Server/bin/directory inside the extracted folder.
Execute the following command to start the axis2server with the SimpleStockQuote back-end service:
To invoke this service, the address URI of this proxy service is defined as
http://localhost:8290/services/SMSSenderProxy. 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>