How to Consume and Produce 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.
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="StockQuoteProxy" transports="jms http https" xmlns="http://ws.apache.org/ns/synapse">
<target>
<inSequence>
<property action="set" name="OUT_ONLY" value="true"/>
<call>
<endpoint>
<address uri=""/> <!-- Specify the JMS connection URL here -->
</endpoint>
</call>
</inSequence>
</target>
<parameter name="transport.jms.ConnectionFactory">myQueueConnectionFactory</parameter>
</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 listens to the 'StockQuoteProxy' queue and sends the messages it receives to another queue named 'SimpleStockQuoteService' |
Property Mediator | The OUT ONLY property is set to true , which indicates that the message exchange is one-way. |
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:
|
Info
Make sure to configure the relevant JMS listener parameters in the deployment.toml
file.
[[transport.jms.listener]]
name = "myQueueConnectionFactory"
parameter.initial_naming_factory = "org.apache.activemq.jndi.ActiveMQInitialContextFactory"
parameter.provider_url = "tcp://localhost:61616"
parameter.connection_factory_name = "QueueConnectionFactory"
parameter.connection_factory_type = "queue"
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).
You now have a running WSO2 Micro Integrator instance, ActiveMQ instance, and a sample back-end service to simulate the sample scenario.
Add a message to the StockQuoteProxy
queue using the ActiveMQ Web Console. You will see the same message published to the SimpleStockQuoteService
.