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/.

Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

Version 1 Next »

Introduction

This sample demonstrates the use of the Transaction Mediator using a sample distributed transaction. For information the mediator, refer to section Transaction Mediator.

Prerequisites

Refer to Prerequisites section in ESB Samples Setup page.

Building the Sample

1. First, let's take a look at the synapse configuration for the ESB used for this sample. It is provided in <ESB_HOME>/repository/samples/synapse_sample_657.xml as shown below:

<definitions xmlns="http://ws.apache.org/ns/synapse"
             xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
             xsi:schemaLocation="http://ws.apache.org/ns/synapse http://synapse.apache.org/ns/2010/04/configuration/synapse_config.xsd">
    <sequence name="myFaultHandler">
        <log level="custom">
            <property name="text" value="** Rollback Transaction**"/>
        </log>
        <transaction action="rollback"/>
        <send/>
    </sequence>
    <sequence name="main" onError="myFaultHandler">
        <in>
            <send>
                <endpoint>
                    <address uri="http://localhost:9000/services/SimpleStockQuoteService"/>
                </endpoint>
            </send>
        </in>
        <out>
            <transaction action="new"/>
            <log level="custom">
                <property name="text" value="** Reporting to the Database esbdb**"/>
            </log>
            <dbreport useTransaction="true" xmlns="http://ws.apache.org/ns/synapse">
                <connection>
                    <pool>
                        <dsName>jdbc/XADerbyDS</dsName>
                        <user>synapse</user>
                        <password>synapse</password>
                    </pool>
                </connection>
                <statement>
                    <sql>delete from company where name =?</sql>
                    <parameter expression="//m0:return/m1:symbol/child::text()"
                               xmlns:m0="http://services.samples"
                               xmlns:m1="http://services.samples/xsd"
                               type="VARCHAR"/>
                </statement>
            </dbreport>
            <log level="custom">
                <property name="text" value="** Reporting to the Database esbdb1**"/>
            </log>
            <dbreport useTransaction="true" xmlns="http://ws.apache.org/ns/synapse">
                <connection>
                    <pool>
                        <dsName>jdbc/XADerbyDS1</dsName>
                        <user>synapse</user>
                        <password>synapse</password>
                    </pool>
                </connection>
                <statement>
                    <sql>INSERT into company values ('IBM','c4',12.0)</sql>
                </statement>
            </dbreport>
            <transaction action="commit"/>
            <send/>
        </out>
    </sequence>
</definitions>

2. Create two database instances to point to sample databases created according to the synapse configuration defined above. For information on creating database instances, refer to Database Instances. Refer the Sample Setup Guide to see how you can set up the derby database server.

3. Create two XA data sources for the database instances created in step 2. For instructions to create data sources, refer to section Data Sources.

4. Start the ESB with the synapse configuration numbered 657 (synapse_sample_657.xml), by running the following command.

  • wso2esb-samples.sh -sn 657 (on Linux)
  • wso2esb-samples.bat -sn 657 (on Windows)

For more information on starting ESB with different synapse configurations, refer to section Starting Sample ESB Configurations.

5. A message should appear in the command or text Linux console stating the server started successfully.

6. Deploy the back-end service SimpleStockQuoteService, and start the Axis2 server using the instructions given in section Starting Sample Back-End Services.

Infor

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

We run this setup using the sample Stock Quote Client, which can operate in several modes. For information on this sample client, refer to section Stock Quote Client.

Execute the following ant command to invoke the sample client.

ant stockquote -Daddurl=http://localhost:9000/services/SimpleStockQuoteService -Dtrpurl=http://localhost:8280/ -Dsymbol=SUN/

In this sample, a record is delete 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 will roll back, and the records will be untouched.

  • No labels