This site contains the documentation that is relevant to older WSO2 product versions and offerings.
For the latest WSO2 documentation, visit https://wso2.com/documentation/.

Distributed Transactions Sample

Note that WSO2 EI is shipped with the following changes to what is mentioned in this documentation:

  • <PRODUCT_HOME>/repository/samples/ directory that includes all Data Integration samples is changed to <EI_HOME>/samples/data-services/.
  • <PRODUCT_HOME>/repository/samples/resources/ directory that includes all artifacts related to the Data Integration samples is changed to <EI_HOME>/samples/data-services/resources/.

Distributed transactions are important when we coordinate multiple transactions across multiple databases. This sample demonstrates the support for distributed transactions in WSO2 Enterprise Integrator (WSO2 EI).

About the sample

The scenario used in this sample data service (DTPSampleService) is based on two banks using separate databases. This data service uses distributed transactions with multiple data sources.

Building the sample

The sample data service DTPSampleService should be deployed using the instructions in Samples Setup section.

Running the sample

The sample service can be run using the TryIt tool, which is bundled with the WSO2 EI, or a code-generated java client sample as discussed in the Data Services Clients section.

Follow the steps below to demonstrate this functionality using the TryIt tool:

  1. Log in to the management console of your server and click List under Services in the navigator. The DTPSampleService will be listed here.
  2. Click Try this service to open the TryIt tool. Execute the following operations:
  3. Run  addAccountToBank1  operation with balance 1000. This creates a new account in bank1 and returns the bank id. Output is as follows:
  4. Run addAccountToBank2 operation with balance 2000. This creates a new account in bank2 and returns the bank id. Output is as follows:
  5. Run the  begin_boxcar  operation. The service will switch to a boxcarring session.
  6. Run the  addToAccountBalanceInBank1  operation and give the values "1" for "accountId" field and "-100" for the "value" field.
  7. Run the  addToAccountBalanceInBank2  operation and give the values "1" for "accountId" field and "h200" for the "value" field. Here we are giving an incorrect value to the "value" field. So, if distributed transaction works correctly, the whole transaction (including the previous operation done on addToAccountBalanceInBank1) should be aborted even though the transaction involves two different databases.
  8. Run the end_boxcar operation.
  9. We can run getAccountBalanceFromBank1 and getAccountBalanceFromBank2 operations to verify that the transactions have aborted and that distributed transaction works properly.
  10. Run the getAccountBalanceFromBank1 operation. The output is as follows:

  11. Run the  getAccountBalanceFromBank2 operation. The output is as follows:
    As we can see, the addAccountToBank1 service call also rolled back because of the error in addAccountToBank2 operation.Â