Tuesday, October 12, 2010

HOW TO MANAGE TRANSACTIONS IN OFM SOA SUITE?

Transactions are part of day to day activity,either booking a online ticket or withdrawing cash from ATM..each and every transaction should be managed so as to compensate the non-availability of any service and to rollback the action performed.,say for example while planning a holiday if money has been debited from your account for hotel booking,renting a car etc but if the Air Ticket is not available then.....
Money should be deposited back into the account..
To manage these scenarios,SOA Suite provides two ways to manage transactions..

First is by using Compensate Handler Activity.
Second by using Global transaction property.

The first scenario involves writing down reverse business logic for compensating the particular event,what you have to do is
Add compensate handler to the scope which needs to be Compensated in case transaction fails
Write reverse business logic inside it for compensating(for eg if transaction involves 3 separate DBAdapter calls for inserting data in different dependent tables,and you want to reverse everything in case any of them fails.)
Add a throw activity in the same scope(lets say Scope2) to throw the exception
Add a catch branch in outer scope say(Scope1),catch the exception and add a compensate activity with scope set as  Scope1
Deploy and test,if Business logic has been written properly your transaction would be compensated.

The Second way is based on the concept of Global Transaction,each composite in itself starts a new transaction when it is called whether it involves 1 or more BPELs

There is a property
<property name="bpel.config.transaction" many="false" type="xs:string">requiresNew</property>
This has to be set in the composite under the particular BPEL component tag.
This makes sure that at the point where the particular BPEL containing transaction is invoked,the current Global Transaction is paused and new one is started and only after successful completion of the particular BPEL,Global Transaction is resumed from the point it let off.
Whenever BPEL containig transaction throws the error,the transaction gets automatically rolled back.
Simple isn't it?