[ Documentation Index ]

WSO2 Enterprise Service Bus (ESB) Transaction support

Contents

Introduction

Transaction plays a major role in today's business world. It adds a very important functionality to your system, which you will only see in a system crash. Having a good transactional support will ensure correct functionality in a system crash. This guide describes the transaction support avilable in WSO2 ESB.


Transaction mediator

A new synpase mediator (transaction mediator) has been added to support the distributed transactions using Java transaction API(JTA). JTA allows applications to perform a distributed transaction that is, transactions that access and update data on two or more networked computer resources (an example would be to have two databases or a database and a message queue such as JMS). This mediator can be used to perform a distributed transaction. The synapse configuration has been extended to add explicit transaction markers. What this means is you can use the synpase configuration language to define the start, end etc.., of your transaction. It's the responsibility of the user to define when to start, commit or rollback the transaction. For example we can mark the start of a transaction at the start of a database commit and end of the transaction at the end of the database commit and we can mark rollback transaction if a failure occurs.

Transaction mediator configuration

Transaction mediator has the following configuration

	    <transaction action="new|use-existing-or-new|fault-if-no-tx|commit|rollback|suspend|resume"/>
        

The action attribute has the following meanings.

new Create a new jta transaction. Generate a fault if a transaction already exist.
use-existing-or-new Create a new jta transaction. Do nothing if a transaction exist.
fault-if-no-tx Generate a fault if no transaction exist. Do nothing if a transaction exist.
commit Commit transaction. Generate a fault if no transaction exist.
rollback Rollback transaction. Generate a fault if no transaction exist.
suspend Suspend transaction. Generate a fault if no transaction exist.
resume Resume transaction. Generate a fault if no transaction exist.

To use the transaction mediator you need to have a JTA provider in your environment. What this mean is you need to deploy WSO2 ESB in an application sever which provide the JTA service. JBoss is an example of such application server. Refer the Reference section to see how you can deploy ESB on JBoss.

An example is avilable in the article(see Reference section) which demostrate the distributed transaction support.


Java Message Service(JMS) transactions

In addition to the distributed transactions, WSO2 ESB also has the support for JMS transactions. The JMS transport which ships with WSO2 ESB has the support for both local and distrbuted transactions.

JMS local transaction

A local transaction represents a unit of work on a single connection to a data source managed by a resource manager. In JMS, we can use the JMS API to get a transacted session and call methods for commit or rollback for the relevant transaction objects. This is managed internal to a resource manager. There is no external transaction manager involved in the coordination of such transactions

JMS local transaction configuration

To start a local JMS transaction you defined following property in JMS transport Listner/Sender in axis2.xml

	    <parameter name="transport.jms.SessionTransacted">true|false</parameter>
        

By default the sesstion is not transacted and if you want to use JMS local transaction set the above parameter to true. And you need to set the following property in synpase fault handler to rollback the transaction in case of a failure.

        <property name="SET_ROLLBACK_ONLY" value="true" scope="axis2"/>
        

There is an example of JMS local transaction in the transaction article(see Reference section).

JMS distribued transaction

WSO2 ESB also has the support for distributed JMS transaction. You can use JMS transport with more than one distributed resources( for example a JMS queue and a remote database server).

Transaction mediator can be used to mark a distributed transaction which involves a distrbution transaction which span through mulitple JMS resources.

The article contains a sample on JMS distributed transaction(see Reference section).

References