How to Implement JMS Synchronous Invocations - Quad Channel JMS-to-JMS¶
The example demonstrates how WSO2 Micro Integrator handles quad-channel JMS synchronous invocations.
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.
See the instructions on how to build and run this example.
<proxy name="QuadJMS" transports="jms" xmlns="http://ws.apache.org/ns/synapse">
<target>
<inSequence>
<property action="set" name="transport.jms.ContentTypeProperty" value="Content-Type" scope="axis2"/>
<log level="full" xmlns="http://ws.apache.org/ns/synapse"/>
<call>
<endpoint>
<address uri="jms:/BEReq?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=BERes"/>
</endpoint>
</call>
<respond/>
</inSequence>
</target>
<parameter name="transport.jms.ContentType">
<rules>
<jmsProperty>contentType</jmsProperty>
<default>text/xml</default>
</rules>
</parameter>
<parameter name="transport.jms.Destination">ClientReq</parameter>
</proxy>
The message flow handled by the sample configuration is as follows:
- The JMSReplyTo property of the JMS message is set to ClientRes . Therefore, the client sends a JMS message to the ClientReq queue.
- The transport.jms.ReplyDestination value is set to BERes. This enables the Micro Integrator proxy to pick messages from the ClientReq queue and send to the BEReq queue.
- The back-end picks messages from the BEReq queue, processes and places response messages to the BERes queue.
- Once a response is available in BERes queue, the proxy service picks the response message, and sends it back to the ClientRes queue.
- The client the message as the response message.
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. |
Property Mediator |
The JMS transport uses the transport.jms.ContentTypeProperty 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.
|
Call 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:
|
Note
Be sure to replace the ' &
' character in the endpoint URL with '&
' 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}
Build and run¶
Create the artifacts:
-
Launch Visual Studio Code with the Micro Integrator for VS Code extension (MI for VS Code) installed.
Info
Follow the Install Micro Integrator for VS Code documentation for a complete installation guide.
-
Create an integration project.
- Create the proxy service 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).
Set up the backend service:
- Download the back-end service.
- Extract the downloaded zip file.
- Open a terminal and navigate to the
axis2Server/bin/
directory inside the extracted folder. -
Execute the following command to start the axis2server with the SimpleStockQuote back-end service:
sh axis2server.sh
axis2server.bat
Invoke the proxy service by sending a simple message.