1

Microsoft.WindowsAzure.StorageClient.RetryPolicy; を使用しようとしました。Azure サービスに接続せずに

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

問題は、InnerRequest メソッドが RetryPolicy を開始するために何をすべきかということです。ある種の指定された例外をスローする必要がありますか?

4

1 に答える 1

5

一時的なエラーは、 Microsoft.Practices.EnterpriseLibrary.WindowsAzure.TransientFaultHandlingアセンブリ (スニペットのStorageTransientErrorDetectionStrategyなど) で使用できるエラー検出戦略によって自動的に検出され、これにより再試行ポリシーがトリガーされます。

実際には、これはMicrosoft.Practices.TransientFaultHandling.Coreアセンブリにあるものに基づいています。Azure 固有のアセンブリの各エラー検出戦略は、次のインターフェイスを実装します。

/// <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);
}

使用するStorageTransientErrorDetectionStrategyの例を次に示します。

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 に答える