问题描述
使用最新的 (12.3.0 在撰写本文时)Nuget 包Azure.Storage.Blobs 组装,并与 BlobServiceClient
类异步上传,我想设置重试选项,以防出现瞬时故障.
Using the latest (12.3.0 at the time of writing) Nuget package for the Azure.Storage.Blobs assembly, and uploading asynchronously with the BlobServiceClient
class, I want to set retry options in case of transient failure.
但没有 UploadAsync()
方法的重载 接受任何带有重试选项的对象:
But no overload of the UploadAsync()
method takes any object with retry options:
UploadAsync(Stream, BlobHttpHeaders, IDictionary<String,String>, BlobRequestConditions, IProgress<Int64>, Nullable<AccessTier>, StorageTransferOptions, CancellationToken)
虽然在创建 BlobServiceClient
时,可以设置 BlobClientOptions
,并且这些确实从抽象基类继承了 RetryOptions
字段ClientOptions
,这个字段是只读的:
And although when creating a BlobServiceClient
, it is possible to set BlobClientOptions
, and these do inherit a RetryOptions
field from the abstract base class ClientOptions
, this field is read only:
// Summary:
// Gets the client retry options.
public RetryOptions Retry { get; }
如何使用 Azure.Storage.Blobs
程序集对 Azure Blob 存储操作设置重试策略?
How do I set a retry policy on an Azure blob storage operation using the Azure.Storage.Blobs
assembly?
推荐答案
您应该在创建 blob 客户端时指定重试部分.这是一个示例:
You should specify the retry part when creating the blob client. Here's a sample:
var options = new BlobClientOptions();
options.Diagnostics.IsLoggingEnabled = false;
options.Diagnostics.IsTelemetryEnabled = false;
options.Diagnostics.IsDistributedTracingEnabled = false;
options.Retry.MaxRetries = 0;
var client = new BlobClient(blobUri: new Uri(uriString:""), options: options);
此外,可以在创建BlobServiceClient
时设置BlobClientOptions
:
In addition, it is possible to set the BlobClientOptions
when creating a BlobServiceClient
:
var blobServiceClient = new BlobServiceClient
(connectionString:storageAccountConnectionString, options: options );
然后您可以使用 BlobServiceClient.GetBlobContainerClient(blobContainerName:"")
和 BlobContainerClient.GetBlobClient(blobName:"")
在一致的方式,有选项.
You can then use BlobServiceClient.GetBlobContainerClient(blobContainerName:"")
and BlobContainerClient.GetBlobClient(blobName:"")
to build the blob URI in a consistent manner, with options.
这篇关于如何使用 Azure.Storage.Blobs 程序集对 Azure blob 存储操作设置重试策略?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!