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.
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 has the following configuration
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.
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.
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
To start a local JMS transaction you defined following property in JMS transport Listner/Sender in axis2.xml
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).
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).