Handling Distributed Transactions
com.atlassian.confluence.content.render.xhtml.migration.exceptions.UnknownMacroMigrationException: The macro 'next_previous_links2' is unknown.

Handling Distributed Transactions

The data integration feature in the ESB profile of WSO2 EI supports data federation, which means that a single data service can expose data from multiple datasources. However, if you have multiple RDBMSs connected to your data service, and if you need to perform IN-ONLY operations (operations that can insert data and modify data in the datasource) in a coordinated manner, the RDBMSs need to be defined as XA datasources.

Let's consider a scenario where you have two MySQL databases. You can define a single data service for these databases and insert data into both as explained below.


Setting up distributed MySQL databases

Follow the steps given below to set up a MySQL database for this tutorial.

  1. Install the MySQL server.

  2. Download the JDBC driver for MySQL from here and copy it to your <EI_HOME>/lib directory.

  3. Set up a database for storing information of offices:

    1. Create a database called OfficeDetails.

      CREATE DATABASE OfficeDetails;
    2. Create the Offices table:

      USE OfficeDetails; CREATE TABLE `Offices` (`OfficeCode` int(11) NOT NULL, `AddressLine1` varchar(255) NOT NULL, `AddressLine2` varchar(255) DEFAULT NULL, `City` varchar(255) DEFAULT NULL, `State` varchar(255) DEFAULT NULL, `Country` varchar(255) DEFAULT NULL, `Phone` varchar(255) DEFAULT NULL, PRIMARY KEY (`OfficeCode`));
  4. Set up a database to store the employee information:

    1. Create a database called EmployeeDetails.

      CREATE DATABASE EmployeeDetails;
    2. Create the Employees table:

      USE EmployeeDetails; CREATE TABLE `Employees` (`EmployeeNumber` int(11) NOT NULL, `FirstName` varchar(255) NOT NULL, `LastName` varchar(255) DEFAULT NULL, `Email` varchar(255) DEFAULT NULL, `JobTitle` varchar(255) DEFAULT NULL, `OfficeCode` int(11) NOT NULL, PRIMARY KEY (`EmployeeNumber`));

Adding the datasources to a data service

Let's create a data service using the Create Data Service wizard:

  1. Start the WSO2 ESB profile.

  2. Access the management console of the ESB profile: https://localhost:9443/carbon

  3. Sign in using admin as the username and password.

  4. On the Data Service menu click Create.

  5. Add a name for the data service and click Next.

  6. Select the Enable Boxcarring and Disable Legacy Boxcarring Mode check boxes.

  7. Click Next to go to the Datasources screen.

  8. Click Add New Datasource to create a datasource connection for the OfficeDetails database:

    Example: The New Datasource screen will now look as follows:

  9. Save the XAoffices datasource.

  10. Click Add New Datasource to create a datasource connection for the EmployeeDetails database as follows:

    Example: The New Datasource screen will now look as follows:

  11. Save the XAemployees datasource and click Next.


Defining queries for the datasources

  1. Click Add New Query to specify an insert query for the XAoffices datasource:

    1. Enter InsertOfficeQuery as the query ID.

    2. Enter the following SQL dialect:

      insert into Offices (OfficeCode,AddressLine1,AddressLine2,City,State,Country,Phone) values(:OfficeCode,:AddressLine1,'test','test','test','USA','test')
  2. Click Generate Input Mapping and the input mappings are generated for the fields in the datasource:

  3. Save the query.

  4. Click Add New Query to specify an insert query for the XAemployees datasource:

    1. Enter InsertEmployeeQuery as the query ID.

    2. Enter the following SQL dialect:

      insert into Employees (EmployeeNumber,FirstName,LastName,Email,JobTitle,OfficeCode) values(:EmployeeNumber,:FirstName,:LastName,'test','test',:OfficeCode)
  5. Click Generate Input Mapping and the input mappings are generated for the fields in the datasource:

  6. Save the query.

  7. Click Next to go to the Operations section. Define operations to invoke the two queries defined above.

    • Create the InsertOfficeOp for the InsertOfficeQuery.

    • Create the InsertEmployeeOp for the InsertEmployeeQuery.

  8. Finish creating the data service.


Inserting data into the distributed RDBMSs

  1. Go to the Deployed Services page and you will see the data service listed.

  2. Click Try this service to open the TryIt tool.

  3. Select the batch operation that is created by default (request_box).

  4. Specify the values that should be inserted to the OfficeDetails database and EmployeeDetails database respectively.

  5. Click Send to invoke the operation.

  6. See that the data is successfully inserted into the two databases.
    Go to the MySQL terminal and run the following commands:

    • Check the office details in the offices table:

      USE OfficeDetails; SELECT * FROM Offices;
    • Check the employee details in the employees table.

      USE EmployeeDetails; SELECT * FROM Employees;
  7. Now, enter another set of values for the two operations but enter an erroneous value for one field.

  8. Invoke the operation.

  9. Check the database tables.
    You see that no records have been entered into either database. 

com.atlassian.confluence.content.render.xhtml.migration.exceptions.UnknownMacroMigrationException: The macro 'next_previous_links' is unknown.