Introduction
There are several occasions where we use Atomic scopes in BizTalk. For instance, invoking a web service proxy as a class library or invoking a custom .NET component. In this article, we shall learn a way to retry/re-execute the code within the Atomic shape several times using a RetryTransactionException
.
Background
If you are new to Atomic scopes and would like to learn more, have a look at my article Parallel Branching and Scoping in BizTalk Orchestrations - Advanced Concepts.
Retrying an Atomic Scope
An Atomic scope does NOT have an exception block, but BizTalk provides a compensation section. In order for an atomic scope to be retried, we shall need to do the following:
- Set the
Retry
property for the scope to True
. - The component invoked must throw an instance of
Microsoft.XLANGs.BaseTypes.RetryTransactionException
class. - Create an sub-scope which shall catch the exception and throw an instance of
Microsoft.XLANGs.BaseTypes.RetryTransactionException
.
The example orchestration below uses the sub-scope approach to retry Atomic scopes.
Orchestration Sample
The above figure depicts the scopes used, to correctly use the RetryTransactionException
exception functionality.
- The orchestration must have the 'Transaction Type' property set to 'Long Running Transaction (LRT)'.
- The Main scope uses a 'Transaction Type' set to 'Long Running Transaction (LRT)'.
- The Main scope contains the Atomic scope.
- The Atomic scope contains a scope (Transaction=NONE) which has an exception block.
The exception block contains the following code...
throw new Microsoft.XLANGs.BaseTypes.RetryTransactionException();
Orchestration Control Flow
The sub-scope contained within an Atomic scope throws an exception, this exception is caught by the exception block of the sub-scope. The expression shape in the exception section throws an instance of RetryTransactionException
.
Takeaways
- Use the
RetryTransactionException
to retry Atomic scopes without having to write an extra line of code. - Throwing the exception
RetryTransactionException
shall retry the Atomic scope atleast 21 times. - Use the property
DelayFor
of the RetryTransactionException
to set the time interval for retry.
History
- 27th January, 2009: Initial post
Naveen has done his Masters (M.S.) in Computer science, has started his career programming the mainframes and now has more than a decade of programming, development and design experience. Naveen has a sharp eye and keen observation skills. Naveen has worked for several companies and strived hard to build large scale business applications and bringing better solutions to the table.
Quite recently Naveen has built a fairly complex integration platform for a large bank. His hobbies include training, mentoring and research. Naveen spends his free time visiting National Parks nationwide.
Naveen has developed the BizTalk Control Center (BCC)
http://biztalkcontrolcenter.codeplex.com