Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

There are two ways to implement transaction in WSO2 ESB as follows.

The ESB can control transactional behavior with a JMS queue and by simulating the Transactional Client EAI pattern. For information on Transactions in WSO2 ESB, refer to Transactions in the WSO2 ESB documentation.

...

Transactional Client EIP (Figure 1)Transactional Client Example Scenario (Figure 2)
Transactional ProducerProxy service inSequence
MessageSimple Stock Quote Request
Transactional ConsumerSimple Stock Quote Service

...

  1. Download and install WSO2 ESB from http://wso2.com/products/enterprise-service-bus. For a list of prerequisites and step-by-step installation instructions, refer to Getting Started Installation Guide in the WSO2 ESB documentation. 
  2. Download and install a JMS server. We use ActiveMQ as the JMS provider in this example.    
  3. In order to enable the JMS transport, edit <ESB_HOME>/repository/conf/axis2/axis2.xml as follows.
    • Uncomment the Axis2 transport listener configuration for ActiveMQ as follows:
      <transportReceiver name="jms" class="org.apache.axis2.transport.jms.JMSListener">...
     
    • Set the transport.jms.SessionTransacted parameter to true. After making this update, the transportReceiversection in axis2.xml should look as follows:

      Code Block
      languagehtml/xml
      <transportReceiver name="jms" class="org.apache.axis2.transport.jms.JMSListener">
              <parameter name="myQueueConnectionFactory" locked="false">
                  <parameter name="java.naming.factory.initial" locked="false">org.apache.activemq.jndi.ActiveMQInitialContextFactory</parameter>
                  <parameter name="java.naming.provider.url" locked="false">tcp://localhost:61616</parameter>
                  <parameter name="transport.jms.ConnectionFactoryJNDIName" locked="false">QueueConnectionFactory</parameter>
              	<parameter name="transport.jms.ConnectionFactoryType" locked="false">queue</parameter>
              	<parameter name="transport.jms.SessionTransacted">true</parameter>
              </parameter>
      
              <parameter name="default" locked="false">
                  <parameter name="java.naming.factory.initial" locked="false">org.apache.activemq.jndi.ActiveMQInitialContextFactory</parameter>
                  <parameter name="java.naming.provider.url" locked="false">tcp://localhost:61616</parameter>
                  <parameter name="transport.jms.ConnectionFactoryJNDIName" locked="false">QueueConnectionFactory</parameter>
                  <parameter name="transport.jms.ConnectionFactoryType" locked="false">queue</parameter>
      			<parameter name="transport.jms.SessionTransacted">true</parameter>
              </parameter>
      </transportReceiver>
    • Uncomment the Axis2 transport sender configuration as follows:
      <transportSender name="jms" class="org.apache.axis2.transport.jms.JMSSender"/>  
  4. Copy the following ActiveMQ client jar files to the <ESB_HOME>/repository/components/lib directory. It allows the ESB to connect to the JMS provider.
    • activemq-core-5.2.0.jar
    • geronimo-j2ee-management_1.0_spec-1.0.jar
     
  5. You need to add a custom mediator called MessageCounterMediator. Download the MessageCounterMediator file and place it in the <ESB_HOME>/repository/components/lib folder. To learn how to write custom mediators, refer to Writing Custom Mediator Implementations in the WSO2 ESB documentation.
  6. Start ActiveMQ (or equivalent JMS Server) and WSO2 ESB.
  7. Start the sample Axis2 server. For instructions, refer to the section Setting Up the ESB Samples Setup - Starting Sample Back-End Servicesthe Axis2 server in the WSO2 ESB documentation.

...

  • class [line 6 in ESB config] - A Custom mediator called MessageCountMediator is loaded. This mediator keeps track of the number of messages that pass through the sequence it calls by updating the value of a variable named MESSAGE_COUNT
  • switch [line 10 in ESB config] - The Switch mediator checks the value of MESSAGE_COUNT
  • case [line 11 in ESB config] - If the value of MESSAGE_COUNT is 1, the transaction is considered to have failed, and no message will be put on the send channel. 
  • default [line 18 in ESB config] - The default action of the switch case flow control. This occurs when the MESSAGE_COUNT is anything but 1. The message is put on the send channel, and the transaction is considered a success.