This documentation is for WSO2 Enterprise Service Bus version 5.0.0. For the latest ESB, view the latest WSO2 Enterprise Integrator documentation.

All docs This doc
Skip to end of metadata
Go to start of metadata


This sample demonstrates how you can load balance messages using the message store and message forwarding processor.


  • Install ActiveMQ and copy the ActiveMQ client JARs activemq-core-5.2.0.jar and geronimo-j2ee-management_1.0_spec-1.0.jar into the <ESB_HOME>/repository/components/lib directory to allow the ESB to connect to the JMS provider.

  • Start ActiveMQ on its default port.
  • For a list of general prerequisites, see Prerequisites to start the ESB samples

Building the sample

The XML configuration for this sample is as follows: 

<definitions xmlns="">
   <registry provider="org.wso2.carbon.mediation.registry.WSO2Registry">
      <parameter name="cachableDuration">15000</parameter>
    <taskManager provider="org.wso2.carbon.mediation.ntask.NTaskTaskManager"/>
   <proxy name="StockQuoteProxy"
          transports="https http"
            <property name="FORCE_SC_ACCEPTED" value="true" scope="axis2"/>
            <property name="OUT_ONLY" value="true"/>
            <store messageStore="JMSMS"/>
   <endpoint name="SimpleStockQuoteService3">
      <address uri="http://localhost:9003/services/SimpleStockQuoteService"/>
   <endpoint name="SimpleStockQuoteService2">
      <address uri="http://localhost:9002/services/SimpleStockQuoteService"/>
   <endpoint name="SimpleStockQuoteService1">
      <address uri="http://localhost:9001/services/SimpleStockQuoteService"/>
   <sequence name="fault">
      <log level="full">
         <property name="MESSAGE" value="Executing default 'fault' sequence"/>
         <property name="ERROR_CODE" expression="get-property('ERROR_CODE')"/>
         <property name="ERROR_MESSAGE" expression="get-property('ERROR_MESSAGE')"/>
   <sequence name="main">
         <log level="full"/>
         <filter source="get-property('To')" regex="http://localhost:9000.*">
      <description>The main sequence for the message mediation</description>
   <messageStore class="" name="JMSMS">
      <parameter name="java.naming.factory.initial">org.apache.activemq.jndi.ActiveMQInitialContextFactory</parameter>
      <parameter name="store.jms.cache.connection">false</parameter>
      <parameter name="java.naming.provider.url">tcp://localhost:61616</parameter>
      <parameter name="store.jms.JMSSpecVersion">1.1</parameter>
      <parameter name="store.jms.destination">JMSMS</parameter>
   <messageProcessor class="org.apache.synapse.message.processor.impl.forwarder.ScheduledMessageForwardingProcessor"
      <parameter name="client.retry.interval">1000</parameter>
      <parameter name="interval">1000</parameter>
      <parameter name="">true</parameter>
   <messageProcessor class="org.apache.synapse.message.processor.impl.forwarder.ScheduledMessageForwardingProcessor"
      <parameter name="client.retry.interval">1000</parameter>
      <parameter name="interval">1000</parameter>
      <parameter name="">true</parameter>
   <messageProcessor class="org.apache.synapse.message.processor.impl.forwarder.ScheduledMessageForwardingProcessor"
      <parameter name="client.retry.interval">1000</parameter>
      <parameter name="interval">1000</parameter>
      <parameter name="">true</parameter>

This configuration file  synapse_sample_705.xml is available in the <ESB_HOME>/repository/samples directory.

To build the sample

  1. Start the ESB with the sample 705 configuration. For instructions on starting a sample ESB configuration, see Starting the ESB with a sample configuration.

    The operation log keeps running until the server starts, which usually takes several seconds. Wait until the server has fully booted up and displays a message similar to "WSO2 Carbon started in n seconds."

  2. Start three instances of the sample Axis2 server on HTTP ports 9001, 9002 and 9003 and give unique names to each server. For instructions on starting the Axis2 server, see Starting the Axis2 server.

  3. Deploy the back-end service SimpleStockQuoteService. For instructions on deploying sample back-end services, see Deploying sample back-end services.

    Now you have a running ESB instance and a back-end service deployed. In the next section, we will send a message to the back-end service through the ESB using a sample client.

Executing the sample

The sample client used here is the Stock Quote Client, which can operate in several modes. For further details on this sample client and its operation modes, see Stock Quote Client.

To execute the sample client

  • Run the following command from the <ESB_HOME>/samples/axis2Client directory:

    ant stockquote -Daddurl=http://localhost:8280/services/StockQuoteProxy -Dmode=placeorder -Dsymbol=WSO2

Analyzing the output

You can analyze the message sent by the ESB to the secure service using TCPMon.

On successful execution of the placeorder request, you will see the following message on the back-end:

Sun Aug 18 10:58:00 IST 2013 :: Accepted order #5 for : 18851 stocks of WSO2 at $ 61.782478265721714

If you use the stockqoute client to send the placeorder request several times and observe the log on the back-end server, you will see that the messages are distributed randomly among the back-end nodes since you send the placeorder request randomly. However, if you send the request message evenly (such as when using soapUI), you will see that the messages are evenly distributed among the back-end nodes.

  • No labels