In a typical ESB cluster, you have several ESBs running in parallel with each having a JMS proxy listening to a single JMS queue. All the ESBs usually have the same back-end. With a setup like this, you have to implement fault tolerance and concurrent processing of JMS messages. Fault tolerance ensures that even when one or more ESBs go down, the system will still keep running until there is at least one ESB in the cluster.
In this clustered setup, Apache ActiveMQ creates a queue by the name of the proxy service. When two ESBs with the same proxy configuration are in the system, ActiveMQ will mark both of them as JMS consumers of a single JMS queue. When the JMS queue gets JMS messages, it will dispatch them to the JMS consumers (ESBs) in a round robin manner.
The ESB configuration of this cluster setup is as follows.
<proxy xmlns="http://ws.apache.org/ns/synapse" name="StockQuoteProxy" transports="jms" statistics="disable" trace="disable" startOnLoad="true"> <target> <inSequence> <log level="full"/> <property name="OUT_ONLY" value="true"/> </inSequence> <outSequence> <send/> </outSequence> <endpoint> <address uri="http://localhost:9000/services/SimpleStockQuoteService"/> </endpoint> </target> <publishWSDL uri="file:repository/samples/resources/proxy/sample_proxy_1.wsdl"/> <parameter name="transport.jms.ContentType"> <rules> <jmsProperty>contentType</jmsProperty> <default>application/xml</default> </rules> </parameter> <description></description> </proxy>
Follow the steps below to configure the cluster and invoke the message flow.
1. Configure two ESB instances to connect with ActiveMQ by copying the relevant jars to <ESB_HOME>/repository/components/lib directory. Both instances should have the same JMS proxy configuration.
2. Increase the port offset value of one ESB instance by editing <ESB_HOME>/repository/conf/carbon.xml file as follows. This is done to ensure that there are no port conflicts by running two WSO2 Carbon instances simultaneously in the same environment.
<!-- 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>
3. Set up the prerequisites given in the Prerequisites section in Setting Up the ESB Samples. Then, deploy the SimpleStockQuoteService client by navigating to <ESB_HOME>/samples/axis2Server/src/SimpleStockQuoteService, and running the ant command in the command prompt or shell script. This will build the sample and deploy the service for you.
4. WSO2 ESB comes with a default Axis2 server, which you can use as the back-end service for this sample. To start the Axis2 server, navigate to <ESB_HOME>/samples/axis2server and run axis2Server.sh (on Linux) or axis2Server.bat (on Windows).
5. Start ActiveMQ and the two ESB instances.
6. Run the JMS client in axis2client using the following command.
ant jmsclient -Djms_type=pox -Djms_dest=dynamicQueues/StockQuoteProxy -Djms_payload=MSFT
The message flow of the cluster is as follow.
The Message Flow
- The JMS client sends a JMS message to the message queue named StockQuoteProxy with information for a stock order.
- When the message goes to the JMS queue, ActiveMQ dispatches the message to one of the JMS proxy services in an ESB. This is done in a round robin manner.
- The JMS proxy then sends the message to the back-end.