![]() |
Enterprise Systems »
Microsoft BizTalk Server »
General
Advanced
HOW To Compensate a Transaction in a BizTalk OrchestrationBy Naveen KaramchettiThis article explains the use of Compensatory Transactions in Orchestrations in BizTalk Server 2006 |
C#, Windows, .NET, Visual Studio, Dev
|
||||||||||
|
Advanced Search |
|
|
|
||||||||||||||||
Most of us are aware of an Atomic transaction, which can either be committed or rolled back. A Long Running (L-R) transaction is one which executes for several hours, days or even weeks and contains several atomic transactions. These smaller atomic transactions which are completed/committed, cannot be rolled back and hence need to be compensated. This undo operation which consists of deleting a record, in the case of an insert operation is known as Compensation and such a transaction is known as a Compensatory Transaction.
BizTalk provides the capabilities and facilities for the compensation to happen, but the developer is responsible for keeping track of all database changes and performing the appropriate undo operations. NOTE: BizTalk does NOT automatically perform compensation. BizTalk Server 2006 and Visual Studio 2005 has been used in this article.
Compensation section is generally written, in order to UNDO the effect of a transaction.
activated only when the scope terminates normally or the scope completes its execution.
Compensation Shape in order for it to execute.
Compensation shape can be used to invoke/execute a compensation section. The control returns to the next operation after compensation shape, once the execution of the compensation section is complete. Consider a scenario where a Employee leave request needs to be processed. The following are the steps which describe it in more detail...
EmployeeLeaveHistory record is inserted into the database as soon as a request arrives in BizTalk. SickLeaveBalance and EarnedLeaveBalance in the Employee table are updated.
SickLeaveBalance or EarnedLeaveBalance remaining for an employee is zero or less than the requested leaves.
EmployeeLeaveHistory record created in the first step needs to be deleted/removed. This is the compensatory transaction.
Stored Procedures used in this scenario.
.NET Component called DBLib, which uses a data class known as LeaveHistoryData
LeaveApplicationSchema
In the Leave Compensation orchestration there are three scopes being used...
The Parent scope is a long running transaction which consists of two Atomic transactions. The First atomic transaction creates a new EmployeeLeaveHistory record. The updation scope updates the columns SickLeaveBalance or EarnedLeaveBalance in the Employee table. The Stored procedure raises an exception when the number of leaves remaining is zero or less than the requested number of leaves. Observe that the exception is caught by the Parent scope and the Compensation Shape invokes the Compensation section of the Leave History Record Insertion Atomic Scope and this section deletes the record or in other words performs an undo operation (Compensatory Transaction).
The RED arrow indicates the flow-of-control from the Compensation Shape to the Compensatory Section.
Observe the event log messages...
The point to note in this example is that the exception raised in the Updation Atomic Scope branch does NOT interrupt the Insertion Atomic Scope branch. The exception is raised only afer the Insertion branch completes its execution.
The RED arrow indicates the flow-of-control from the Compensation Shape to the Compensatory Section.
EmployeeDB.zip into the SQL 2005 Database Server on your box.
C:\ drive.
LeaveRequestMessage in the In folder and check the Event Viewer. Synchronized property on the Scope shape to true, in the case you want to handle exceptions.
General
News
Question
Answer
Joke
Rant
Admin
|
PermaLink |
Privacy |
Terms of Use
Last Updated: 12 May 2006 Editor: |
Copyright 2006 by Naveen Karamchetti Everything else Copyright © CodeProject, 1999-2009 Web11 | Advertise on the Code Project |