This documentation is for WSO2 Data Services Server 3.5.0. View documentation for the latest release.
Distributed Transactions Sample - Data Services Server 3.5.0 - WSO2 Documentation
Due to a known issue do not use JDK1.8.0_151 with WSO2 products. Use JDK 1.8.0_144 until JDK 1.8.0_162-ea is released.
Skip to end of metadata
Go to start of metadata

Distributed transactions are important when we coordinate multiple transactions across multiple databases. This sample demonstrates the support for distributed transactions in WSO2 Data Services Server.

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 Data Services Server, 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. 
  • No labels