This sample demonstrates theusing a sample distributed transaction. In this sample, a record is delete from one database and added to a second database. If either of the operations (deleting from the first database and adding to the other) fails, all operations will roll back, and the records will be untouched.
Also, see Transaction Mediator.
For a list of prerequisites, see the Prerequisites section in Setting up the ESB Samples.
Building the sample
1. First, let's take a look at the synapse configuration used for this sample.
2. The above sample configuration usesto point to the sample databases. You have to manually create these in your environment for the sample to work.
- For information on creating database instances, see Setting Up the Physical Database. See Setting up the ESB Samples for information on how you can set up the Derby database server.
- For information on creating the two sample XA data sources, see Adding Datasources and Transaction Examples
3. Start the ESB server and log into its management console UI (
//). In the management console, navigate to Main Menu, click Service Bus and then Source View. Next, copy and paste the above synapse configuration, which helps you explore the example scenario, to the source view
4. Deploy the back-end service SimpleStockQuoteService, and start the Axis2 server using the instructions given in section Starting Sample Back-End Services.
WSO2 ESB comes with a default JTA transaction manager (Atomikos), which allows you to run distributed transactions without deploying the ESB on an external application server.
You now have a running ESB instance, databases and a back-end service deployed in your environment.
Executing the sample
We run this setup using the sample Stock Quote Client, which can operate in several modes. For information on this sample client, refer to section Stock Quote Client.
Execute the following ant command to invoke the sample client.
You can try deleting a record from one database and adding to a second database. Simulate a failure scenario and notice how all operations roll back, and none of the records gets affected.