JMS messaging with ESB and MB
This post describes how to integrate WSO2 ESB(Enterprise Service Bus) with WSO2 MB (Message Broker) to facilitate message brokering.
As prerequisites you need to download [1] & [2].
[1] WSO2 ESB 4.8.0 - http://wso2.com/products/enterprise-service-bus/
[2] WSO2 MB 2.1.0 - http://wso2.com/products/message-broker/
Please note that WSO2 uses same port (0) as the default port in all products' configuration, since we cannot start multiple products with the same port in the same environment we need to change either ports in order to avoid port conflicts. In this example I have changed the port of MB to 1.
Configure MB:
1. Change the offset.
Go to <Product Home>/repository/conf/carbon.xml and change the offset to 1
<Ports>
<!-- Ports offset. This entry will set the value of the ports defined below to
the define value + Offset.
e.g. Offset=2 and HTTPS port=9443 will set the effective HTTPS port to 9445
-->
<Offset>1</Offset>
2. Start MB
Run <MB_HOME>/bin/wso2server.sh (on Linux) or <MB_HOME>/bin/wso2server.bat (on Windows)
Configure ESB:
1. Enable the JMS transport
This is needed to communicate with the MB. You can do this by uncommenting transport receiver and transport sender.
Go to <ESB_HOME>/repository/conf/axis2/axis2.xml file and find the commented <transport receiver> and uncomment it. Then find the <transport sender> and uncomment it as well.
2. Copy relevant client libraries of MB to ESB
Go to <MB_HOME>/clent-lib folder and copy the below mentioned libraries and paste it to <ESB_HOME>/repository/components/lib folder.
- andes-client-0.13.wso2v8
- geronimo-jms_1.1_spec-1.1.0.wso2v1
Go to the <ESB_HOME>/repository/conf/ JNDI.proerties file and define a queue. I have defined a queue called TestStockQuotesQueue. In order to avoid getting 'javax.naming.NameNotFoundException: TopicConnectionFactory’ during server startup, point 'TopicConnectionFactory' also to the Message Broker
3. Point to the running MB
# register some connection factories
# connectionfactory.[jndiname] = [ConnectionURL]
connectionfactory.QueueConnectionFactory = amqp://admin:admin@clientID/carbon?
brokerlist='tcp://localhost:5673'
connectionfactory.TopicConnectionFactory = amqp://admin:admin@clientID/carbon?
brokerlist='tcp://localhost:5673'
# register some queues in JNDI using the form
# queue.[jndiName] = [physicalName]
queue.TestStockQuotesQueue = TestStockQuotesQueue
|
Run <ESB_HOME>/bin/wso2server.sh (on Linux) or <ESB_HOME>/bin/wso2server.bat (on Windows).
For testing purposes I have used the SimpleStockQuoteService.
- Go to <ESB_HOME>/samples/axis2Server/src/SimpleStockQuoteService and run ‘ant’ to build the sample and deploy background services.
- Then run <ESB_HOME>/samples/axis2server/ axis2Server.sh (on Linux) to start the Axis2 server. Now you can see the service is available at http://127.0.0.1:9000/services/SimpleStockQuoteService
1. Here I am going to create the consumer first. Create a JMS proxy by the name “TestStockQuotesQueue”. Please note this name should be as same as the name defined in the jndi.properties file. In here the message which is consumed from the JMS queue is sent to the relevant endpoint.
Setting up the backend:
The out only scenario
In this scenario is I am going to store a message received to a http proxy of the ESB in a JMS queue. Then consume that queue and get the message and finally send it to the actual endpoint.
<proxy xmlns="http://ws.apache.org/ns/synapse" name="TestStockQuotesQueue"
transports="jms" statistics="disable" trace="disable" startOnLoad="true">
<target>
<inSequence>
<log level="full"/>
<property name="OUT_ONLY" value="true"/>
<send>
<endpoint>
<address uri="http://localhost:9000/services/SimpleStockQuoteService"/>
</endpoint>
</send>
</inSequence>
</target>
<description></description>
</proxy>
2. Then I am going to create HTTP proxy to be used to send the message to JMS queue.
<proxy xmlns="http://ws.apache.org/ns/synapse" name="TestStockQuoteProxy" transports="https,http" statistics="disable" trace="disable" startOnLoad="true">
<target>
<inSequence>
<property name="OUT_ONLY" value="true"/>
<property name="FORCE_SC_ACCEPTED" value="true" scope="axis2"/>
<send>
<endpoint>
<address uri="jms:/TestStockQuotesQueue?transport.jms.ConnectionFactoryJNDIName=QueueConnectionFactory&java.naming.factory.initial=org.wso2.andes.jndi.PropertiesFileInitialContextFactory&java.naming.provider.url=repository/conf/jndi.properties&transport.jms.DestinationType=queue"/>
</endpoint>
</send>
</inSequence>
</target>
<description></description>
</proxy>
Now when the 'TestStockQuoteProxy' is invoked, it will send the message to the queue. Then the message will be consumed by the JMS proxy 'TestStockQuotesQueue' and send to the actual endpoint.
Execute the scenario
You can use SOAP UI to send a request to 'TestStockQuoteProxy' and can see the message has been logged in ESB console and the output will be in the axis2server.
No comments:
Post a Comment