Jaa


What Does the Transient Fault Handling Application Block Do?

Retired Content

This content and the technology described is outdated and is no longer being maintained. For more information, see Transient Fault Handling.

patterns & practices Developer Center

The Transient Fault Handling Application Block can apply retry policies to operations that your application performs against services that may exhibit transient faults. This makes it easier to implement consistent retry behavior for any transient faults that may affect your application.

The Transient Fault Handling Application Block uses detection strategies to identify all known transient error conditions. You can use one of the built-in detection strategies for SQL Azure, Microsoft Azure Storage, Azure Caching, or the Azure Service Bus. You can also define detection strategies for any other services that your application uses.

The Transient Fault Handling Application Block enables you to define retry policies based on the built-in retry strategies. You can also define your own custom retry strategies.

The following table describes the built-in retry strategies in the Transient Fault Handling Application Block.

Name

Example

Fixed interval

Retry four times at one-second intervals

Incremental interval

Retry four times, waiting one second before the first retry, then two seconds before the second retry, then three seconds before the third retry, and four seconds before the fourth retry.

Exponential back off

Retry four times, waiting two seconds before the first retry, then four seconds before the second retry, then eight seconds before the third retry, and sixteen seconds before the fourth retry.

This retry strategy also introduces a small amount of random variation into the intervals. This can be useful if the same operation is being called multiple times simultaneously by the client application.

The following code sample shows a simple example of using the Transient Fault Handling Application Block.

using Microsoft.Practices.TransientFaultHandling;
using Microsoft.Practices.TransientFaultHandling.RetryStrategies;
using Microsoft.Practices.EnterpriseLibrary.WindowsAzure.TransientFaultHandling.AzureStorage;

...
// Define your retry strategy: retry 3 times, 1 second apart.
var retryStrategy = new FixedInterval(3, TimeSpan.FromSeconds(1));

// Define your retry policy using the retry strategy and the Azure storage
// transient fault detection strategy.
var retryPolicy = 
  new RetryPolicy<StorageTransientErrorDetectionStrategy>(retryStrategy);

// Do some work that may result in a transient fault.
try
{
  // Call a method that uses Azure storage and which may
  // throw a transient exception.
  retryPolicy.ExecuteAction(
    () =>
    {
        this.queue.CreateIfNotExist();
    });
}
catch (Exception)
{
  // All of the retries failed.
}

In many cases, immediately retrying the operation that failed as a result of a transient condition will result in the operation succeeding. By default, the block is configured to perform the first retry immediately.

The Transient Fault Handling Application Block can notify your application whenever it detects a transient fault condition and whenever it performs a retry. You application can then log information about retries that have occurred.

Next Topic | Previous Topic | Home

Last built: June 7, 2012