支持 Azure Table 存储中的 RetyPolicy WindowsAzure.Storage SDK 版本 7.0.0.0

Support for RetyPolicy in Azure Table Storage for WindowsAzure.Storage SDK version 7.0.0.0

我需要为所有 Table 操作应用自定义重试策略。这是我一直在使用的:

_account = CloudStorageAccount.Parse(PhoenixConfiguration.AzureBlobStorageConnection);
var _tableClient = this._account.CreateCloudTableClient();
IRetryPolicy linearRetryPolicy = new LinearRetry(TimeSpan.FromSeconds(5), 10);
_tableClient.RetryPolicy = linearRetryPolicy;

我正在使用 WindowsAzure.Storage SDK(版本 6),在将我的项目升级为使用 WindowsAzire.Storage SDK 版本 7 后,此代码已损坏。在新 SDK 中实现自定义重试策略的正确方法是什么?有没有我可以参考的文档?

您的代码无法编译的原因是 CloudTableClient 上的 RetryPolicy 成员在 6.0 版中已被弃用,现在在 7.0 版中被删除 [令人惊讶的是它仍然存在于 CloudBlobClient,尽管它已被弃用。

为了使用 Retry Polcies,您必须使用 TableRequestOptions 并在那里指定重试策略。例如,这就是创建 table.

时可以使用它的方式
        var storageAccount = new CloudStorageAccount(new StorageCredentials(accountName, accountKey), true);
        IRetryPolicy linearRetry = new LinearRetry(TimeSpan.FromSeconds(5), 10);
        var tableClient = storageAccount.CreateCloudTableClient();
        var table = tableClient.GetTableReference("MyTable");
        var tableRquestOptions = new TableRequestOptions()
        {
            RetryPolicy = linearRetry
        };
        table.CreateIfNotExists(tableRquestOptions);