Apache Synapse

##### Main Menu

- Home
- Download
- History
- License
- Thanks
- Sponsorship
- Security

##### Documentation

- Installation Guide
- Quick Start Guide
- Samples Setup Guide
- Samples Catalog
- Configuration Language
- Mediators Catalog
- Transports Catalog
- Extending Synapse
- Upgrading
- Deployment
- Javadocs
- FAQ

##### Developer Resources

- Developer Guide
- Development Best Practices
- Release Process

##### Project Details

- Overview
- Mailing Lists
- Source Repository
- Issue Tracking
- Dependencies
- Project Team
- Project Summary

##### Previous Releases

- Version 1.2
- Version 1.1.1
- Version 1.1
- Version 1.0

## Sample 410: Distributed Transactions Management with the Transaction Mediator

<definitions xmlns="http://ws.apache.org/ns/synapse" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://ws.apache.org/ns/synapse http://synapse.apache.org/ns/2010/04/configuration/synapse_config.xsd"> <sequence name="myFaultHandler"> <log level="custom"> <property name="text" value="** Rollback Transaction**"/> </log> <transaction action="rollback"/> <send/> </sequence> <sequence name="main" onError="myFaultHandler"> <in> <send> <endpoint> <address uri="http://localhost:9000/services/SimpleStockQuoteService"/> </endpoint> </send> </in> <out> <transaction action="new"/> <log level="custom"> <property name="text" value="** Reporting to the Database esbdb**"/> </log> <dbreport useTransaction="true" xmlns="http://ws.apache.org/ns/synapse"> <connection> <pool> <dsName>java:jdbc/XADerbyDS</dsName> <icClass>org.jnp.interfaces.NamingContextFactory</icClass> <url>localhost:1099</url> <user>synapse</user> <password>synapse</password> </pool> </connection> <statement> <sql>delete from company where name =?</sql> <parameter expression="//m0:return/m1:symbol/child::text()" xmlns:m0="http://services.samples" xmlns:m1="http://services.samples/xsd" type="VARCHAR"/> </statement> </dbreport> <log level="custom"> <property name="text" value="** Reporting to the Database esbdb1**"/> </log> <dbreport useTransaction="true" xmlns="http://ws.apache.org/ns/synapse"> <connection> <pool> <dsName>java:jdbc/XADerbyDS1</dsName> <icClass>org.jnp.interfaces.NamingContextFactory</icClass> <url>localhost:1099</url> <user>synapse</user> <password>synapse</password> </pool> </connection> <statement> <sql>INSERT into company values ('IBM','c4',12.0)</sql> </statement> </dbreport> <transaction action="commit"/> <send/> </out> </sequence> </definitions>

### Objective

Demonstrate how to manage complex distributed transactions using the transaction mediator

### Pre-requisites

- To run this sample it is required to deploy Synpase on JBoss application server(This is only tested with JBoss application sever). You can use the Synapse war distribution to deploy Synapse on JBoss. Use the synpase_sample_410.xml as the synapse confiuration file and start JBoss. Also you need to define two XA datasources for above the two datasources defined in Synapse. You'll need to refer JBoss documentation to see how to do this.
- Setup two Derby database instances as described in the database setup guide. These databases will be used by the XA datasources in JBoss.
- Deploy the SimpleStockQuoteService in the sample Axis2 server and start Axis2

### Executing the Client

In this sample a record is deleted from one database and it is added to the second database. If either of the operations(deleting from the 1st database and adding to the second database) fails the entire operation will be roll backed. The records will be left intact.

Invoke the client as follows to try this out.

ant stockquote -Daddurl=http://localhost:9000/services/SimpleStockQuoteService -Dtrpurl=http://localhost:8280/ -Dsymbol=SUN

You can force an error by shutting down one of the two database instances.

Back to Catalog