Transactions are implemented in Orchestrations using Atomic Scope. An Atomic Scope supports ACID properties of Transactions where as Long Running Scope Supports C&D properties of ACID.
An atomic scope either executes completely or it will not execute at all.
There are two other Advantages of Atomic scope in addition to supporting Transactions.
1. Non-Serializable classes can be called from an Atomic Scope.
2. The number of Persistence points within an Orchestration can be reduced as an atomic scope will always induce one Persistence point (at the end of the scope).
Below is the sample which will gives you a clear idea of achieving Transactions using Atomic Scope.
1. Create a schema with two nodes Type and Value of string data type. Make them as distinguished for ease of use.
We will use Type Field to check whether it uses Atomic Scope or Normal Scope with in an Orchestration. A value of Atomic will cause the orchestration to call the Atomic Branch. A value of Normal will cause the Orchestration to call Normal Branch.
We will use the Value field to check whether to throw an exception or not. A value of 1 will throw an exception while others will not throw an exception.
2. Create an Orchestration that receives the message of type Schema created in step 1.
3. Add shapes to the Orchestration to achieve as shown below.
i. Orchestration itself should be set as Long Running. For this click on the white space and set the Transaction Type to Long Running.
ii. Main Scope should also be set as Long Running. An atomic scope cant be placed within a Normal Scope.
iii. The if condition will check whether to call Atomic scope or Normal Scope. If Message_1 is the message received, then give the condition as
Message_1.Type == “Atomic”
iv. Scope on the First Branch of If condition will be set as Atomic. Scope on the right side is set as Normal.
v. Delay shape is set for a delay of 20 seconds.
vi. Throw expression shape will throw an exception based if the value element of the input message.
if(Message_1.Value == “1”)
throw new System.Exception();
4. Sign the project and deploy it.
5. For Testing use the below files.
Test Input 1
Test Input 2
Test Input 3
Test Input 4
1. When you use Input 1, you will find that the message will be saved to the output Folder after 20 Seconds. Because, the Atomic will not commit until all the shapes execute successfully.
2. When you use Input 2, you will find that the no message is written the output folder. Because there is an exception thrown after the Send Shape. However a message should appear in the Exception Send Folder.
3. When you use Input 3, you will find that the message will be saved to the output Folder Immediately. There won’t be any delay in saving the file unlike Input1.
4. When you use Input 4, you will find that the message will be saved to the output Folder as well as exception folder. Because the exception occurred after the send shape, changes are not reverted.
The result would be same whether you use File Adapter or SQL Adapter. However I didn’t test with other Adapters.
Please note that, the scope of BizTalk with respect to Atomic Transaction is till BizTalk Server Message Box only. Please consider this before you decide to use Atomic scope.
Hope it helps.