1

I tried to use Microsoft.WindowsAzure.StorageClient.RetryPolicy; without connecting to Azure services

var _retry = RetryPolicyFactory.GetRetryPolicy<StorageTransientErrorDetectionStrategy>("Incremental Retry Strategy");
  var result = _retry.ExecuteAction(()=> InnerRequest(data));

the question is - what should do InnerRequest method do to RetryPolicy began work? it should throw some sort of specified exception?

4

1 回答 1

5

Transient errors are detected automatically by the error detection strategies available in the Microsoft.Practices.EnterpriseLibrary.WindowsAzure.TransientFaultHandling assembly (like the StorageTransientErrorDetectionStrategy in your snippet), and this will trigger the retry policy.

In reality, this is based on what you can find in the Microsoft.Practices.TransientFaultHandling.Core assembly. Each error detection strategy in the Azure specific assembly implements the following interface:

/// <summary>
/// Defines an interface which must be implemented by custom components responsible for detecting specific transient conditions.
/// </summary>
public interface ITransientErrorDetectionStrategy
{
    /// <summary>
    /// Determines whether the specified exception represents a transient failure that can be compensated by a retry.
    /// </summary>
    /// <param name="ex">The exception object to be verified.</param>
    /// <returns>True if the specified exception is considered as transient, otherwise false.</returns>
    bool IsTransient(Exception ex);
}

Here is an example of the StorageTransientErrorDetectionStrategy you use:

WebException webException = ex as WebException;
if (webException != null && (webException.Status == WebExceptionStatus.ProtocolError || webException.Status == WebExceptionStatus.ConnectionClosed))
{
    return true;
}
DataServiceRequestException dataServiceException = ex as DataServiceRequestException;
if (dataServiceException != null && StorageTransientErrorDetectionStrategy.IsErrorStringMatch(StorageTransientErrorDetectionStrategy.GetErrorCode(dataServiceException), new string[]
{
    "InternalError", 
    "ServerBusy", 
    "OperationTimedOut", 
    "TableServerOutOfMemory"
}))
{
    return true;
}
StorageServerException serverException = ex as StorageServerException;
if (serverException != null)
{
    if (StorageTransientErrorDetectionStrategy.IsErrorCodeMatch(serverException, new StorageErrorCode[]
    {
        1, 
        2
    }))
    {
        return true;
    }
    if (StorageTransientErrorDetectionStrategy.IsErrorStringMatch(serverException, new string[]
    {
        "InternalError", 
        "ServerBusy", 
        "OperationTimedOut"
    }))
    {
        return true;
    }
}
StorageClientException storageException = ex as StorageClientException;
return (storageException != null && StorageTransientErrorDetectionStrategy.IsErrorStringMatch(storageException, new string[]
{
    "InternalError", 
    "ServerBusy", 
    "TableServerOutOfMemory"
})) || ex is TimeoutException;
于 2012-04-11T07:05:17.733 回答