65.9K
CodeProject is changing. Read more.
Home

HOW TO Retry Atomic Scopes using RetryTransactionException

starIconstarIconstarIconstarIcon
emptyStarIcon
starIcon

4.78/5 (2 votes)

Jan 27, 2009

CPOL

2 min read

viewsIcon

32240

downloadIcon

200

This article describes how to retry a atomic scope execution using a RetryTransactionException

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:

  1. Set the Retry property for the scope to True.
  2. The component invoked must throw an instance of Microsoft.XLANGs.BaseTypes.RetryTransactionException class.
  3. 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