This documentation is for WSO2 Enterprise Service Bus version 4.8.1 . View documentation for the latest release.

All docs This doc

Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

This sample demonstrates the functionality of the Transaction Mediator using 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 will do not change.

Prerequisites

  • For a list of general prerequisites, see Setting Up the ESB Samples.
  • The sample configuration uses two datasources and database instances 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.

      Code Block
      SQL
      SQL
      CREATE table company(name varchar(10) primary key, id varchar(10), price double);
    • Create a table in esbdb1 by executing the following statement.

      Code Block
      SQL
      SQL
      CREATE table company(name varchar(10) primary key, id varchar(10), price double);
    • Insert records into the two tables that you created by executing the following statements.

      To insert records into the table in esbdb

      Code Block
      SQL
      SQL
      INSERT into company values ('IBM','c1',0.0);
      INSERT into company values ('SUN','c2',0.0);
      

      To insert records into the table in esbdb1

      Code Block
      SQL
      SQL
      INSERT into company values ('SUN','c2',0.0);
      INSERT into company values ('MSFT','c3',0.0);
      
      Info
      titleNote

      When inserting records into the tables, the order of the record matters.

    • In the master-datasources.xml file located in the <ESB_HOME>/repository/conf/datasources directory, create datasource declarations for the distributed databases, ensuring that the datasource file names are *-xa-ds.xml:
      Datasource1: esb-derby-xa-ds.xml

      Code Block
      XML
      XML
      <datasources>
          <xa-datasource>
              <jndi-name>jdbc/XADerbyDS</jndi-name>
              <isSameRM-override-value>false</isSameRM-override-value>
              <xa-datasource-class>org.apache.derby.jdbc.ClientXADataSource</xa-datasource-class>
              <xa-datasource-property name="portNumber">1527</xa-datasource-property>
              <xa-datasource-property name="DatabaseName">esbdb</xa-datasource-property>
              <xa-datasource-property name="User">esb</xa-datasource-property>
              <xa-datasource-property name="Password">esb</xa-datasource-property>
              <metadata>
                  <type-mapping>Derby</type-mapping>
              </metadata>
          </xa-datasource>
      </datasources>
      

      Datasource2: esb-derby1-xa-ds.xml

      Code Block
      XML
      XML
      <datasources>
          <xa-datasource>
              <jndi-name>jdbc/XADerbyDS1</jndi-name>
              <isSameRM-override-value>false</isSameRM-override-value>
              <xa-datasource-class>org.apache.derby.jdbc.ClientXADataSource</xa-datasource-class>
              <xa-datasource-property name="portNumber">1527</xa-datasource-property>
              <xa-datasource-property name="DatabaseName">esbdb1</xa-datasource-property>
              <xa-datasource-property name="User">esb</xa-datasource-property>
              <xa-datasource-property name="Password">esb</xa-datasource-property>
              <metadata>
                  <type-mapping>Derby</type-mapping>
              </metadata>
          </xa-datasource>
      </datasources>
      

...