Note that WSO2 EI is shipped with the following changes to what is mentioned in this documentation:
repository/samples/directory that includes all Integration profile samples is changed to
repository/samples/resources/directory that includes all artifacts related to the Integration profile samples is changed to
This sample demonstrates the functionality of theusing a sample distributed transaction. In this sample, a record is deleted 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 rollback, and the records do not change.
- For a list of general prerequisites, see Setting Up the Service Bus Samples.
- The sample configuration uses
to point to the sample databases. You have to manually create these in your environment for the sample to work.
Setup two distributed Derby databases esbdb and esbdb1. For instructions on setting up the Derby databases, see Setting up Remote Derby.
Create a table in esbdb by executing the following statement.
Create a table in esbdb1 by executing the following statement.
Insert records into the two tables that you created by executing the following statements.
To insert records into the table in esbdb
To insert records into the table in esbdb1
When inserting records into the tables, the order of the record matters.
Add the required datasource via the Management Console or create datasource declarations for the distributed databases In the
master-datasources.xmlfile. For information on how you can add datasources via the management console, see Adding Datasources. To create datasource declarations In the
master-datasources.xmlfile, add the following code segments in the
master-datasources.xmlfile located in the <
ESB_HOME>/repository/conf/datasourcesdirectory, ensuring that the datasource file names are
Building the sample
The XML configuration for this sample is as follows:
This configuration file
synapse_sample_657.xml is available in the
To build the sample
Start the ESB with the sample 657 configuration. For instructions on starting a sample ESB configuration, see Starting the ESB with a sample configuration.
The operation log keeps running until the server starts, which usually takes several seconds. Wait until the server has fully booted up and displays a message similar to "WSO2 Carbon started in n seconds."
Start the Axis2 server. For instructions on starting the Axis2 server, see Starting the Axis2 server.
Deploy the back-end service SimpleStockQuoteService. For instructions on deploying sample back-end services, see Deploying 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
The sample client used here is the Stock Quote Client, which can operate in several modes. For further details on this sample client and its operation modes, see Stock Quote Client.
To execute the sample client
Execute the following command from the
<ESB_HOME>/samples/axis2Clientdirectory to test the successful scenario.
Execute the following command from the
<ESB_HOME>/samples/axis2Clientdirectory to test the failure scenario.
Analyzing the output
When you run the client to test the successful scenario, you will see that the IBM record is removed from the first database and added to the second database.
When you run the client to test the failure scenario, you will see that a record is neither deleted from the first database nor added into the second database. That is because executing the command attempts to add an already existing record again to the second database, which results in the fault sequence being executed. Therefore, an exception raised for duplicate entries and results in an entire transaction rollback.