Sample 652: Distributed transaction management
<definitions xmlns="http://ws.apache.org/ns/synapse">
<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 the use of the transaction mediator in a distributed transaction
Pre-requisites
-
Deploy the SimpleStockQuoteService in the sample Axis2 server and start Axis2
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 war distribution to deploy synapse on JBoss application server. Use the synpase_sample_652.xml as the synapse confiuration
file and start JBoss with that synpase configuration file. Also you need to define two XA datasources for above two datasources.
You'll need to refer JBoss documentation to see how to do this.
It also required to have two database instances, this will be used by the two XA datasources.
Refer the Sample Setup Guide to see how you can set up the derby database server.
In this sample a record is delete from one database and it is added into the second database.
If either of the operations(deleting from the 1st database and adding into the second database)
fails everything will be roll backed. The records will be untoched.
-
Start Synapse using the configuration numbered 652 (repository/conf/sample/synapse_sample_652.xml)
Unix/Linux: sh synapse.sh -sample 652
Windows: synapse.bat -sample 652
Executing the Client
ant stockquote -Daddurl=http://localhost:9000/services/SimpleStockQuoteService -Dtrpurl=http://localhost:8280/
Sat Nov 18 21:01:23 IST 2006 SimpleStockQuoteService :: Generating quote for : IBM
Standard :: Stock price = $95.26454380258552
Back to Catalog