【问题标题】:Support for RetyPolicy in Azure Table Storage for WindowsAzure.Storage SDK version 7.0.0.0Azure Table Storage for WindowsAzure.Storage SDK 版本 7.0.0.0 支持 RetyPolicy
【发布时间】:2016-08-15 17:19:36
【问题描述】:

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

_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 中实施自定义重试策略的正确方法是什么?有没有我可以参考的文档?

【问题讨论】:

  • 你遇到了什么错误?
  • 编译错误。 TableClient 类似乎不再支持 RetryPolicy 属性。

标签: azure azure-storage azure-table-storage azure-sdk-.net


【解决方案1】:

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

为了使用Retry Polcies,您必须使用TableRequestOptions 并在那里指定重试策略。例如,这就是您在创建表时可以使用它的方式。

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

【讨论】:

  • 感谢您的回答。尽管 RetryPolicy 仍然存在 BlobClient,但我在运行时遇到了一个奇怪的错误。我的本地模拟器抛出一个错误,说该操作是不允许的。
  • 嗯...我自己没有尝试过,所以我不知道。但我建议不要在客户端对象上指定重试策略,而是在操作级别指定,因为它们可能随时被取消。
猜你喜欢
  • 1970-01-01
  • 2022-01-20
  • 2012-01-25
  • 1970-01-01
  • 1970-01-01
  • 2019-08-12
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多