...
A new Synapse mediator (transaction mediator) has been added. It supports distributed transaction using Java transaction API (JTA)2. 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 mean is you can use the Synapse configuration language to define the start, end etc., of your transaction. Its 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 the transaction at the end of the database commit and we can mark rollback transaction in case of a failure occurring.
Transaction mediator configuration
...
Unzip WSO2 ESB distribution to a place of your choice. And then remove the geronimo-jta_1.1_spec-1.1.0.wso2v1.jar
( This JAR file can be found in $ESB_HOME/repository/components/plugins
). The reason is using of the implementation of javax.transaction.UserTransaction
6 of JTA provider (here JBoss) and if we have both in class path, there is a classloading issue which causes the transaction mediator not to work.
We need to deploy WSO2 ESB on JBoss AS. See 7 to see how this can be done. The JBOSS installation path will be referred to as $JBOSS_HOME
and the WSO2 ESB repo location as $CARBON_HOME
.
Drop the derby client JARs (derby.jar
, derbynet.jar
and derbyclient.jar
) into $CARBON_HOME/repository/components/lib
folder and also into $JBOSS_HOME/server/default/lib
(we'll use the default JBoss configuration) folder.
We will use a sample similar to #3618#3618, and the full Synapse configuration is shown below (you can directly paste the following configuration into synapse configuration in $ESB_HOME/repository/conf/synapse-config/synapse.xml
). In the in sequence, we will send a message to the service and in the out sequence, we will delete an entry from the first database and will update the second database with that entry. If we try to add an entry which is already there in the second database, the whole transaction will be roll-backed.
...
Now go into $JBOSS_HOME/bin
and start the server. Just run the run.sh (run.bat) script. Note that you need to set the CARBON_HOME
enviornment varible pointing to the Carbon repository location.
Now we can try the samples. See sample set up guide9 guide9 to see how you can set up the server. We need to deploy the SimpleStockQuote
service which comes with WSO2 ESB sampels.
...
In the following scenario, a message is read from a JMS queue and it is processed by a back end service. While executing one sequence ESB receives a fault and this causes the JMS transaction to rollback. In the successful scenario, the transaction is committed and the request is sent to the backend service. In the following configuration, there is a class mediator which will set a property called "MESSAGE_COUNT" to the message context and it will demonstrate this behavior. Depending on the value of this variable the decision to either commit or rollback the transaction will be taken. You can download the binary ZIP of the mediator from here 23. Drop this mediator to $ESB_HOME/repository/components/lib
.
...
Some efforts are in progress to add the support for using a stand alone JTA provider such as Atomikos10Atomikos10.
Excerpt | ||
---|---|---|
| ||
Description of transactional ESB and examples. |