簡體   English   中英

如何使用 Azure.Storage.Blobs 程序集對 Azure blob 存儲操作設置重試策略?

[英]How do I set a retry policy on an Azure blob storage operation using the Azure.Storage.Blobs assembly?

使用(最新12.3.0在寫作的時候)的NuGet包為Azure.Storage.Blobs組裝和異步上傳與BlobServiceClient類,我想在瞬時故障的情況下設定的重試選項。

但是UploadAsync()方法的重載不接受任何帶有重試選項的對象:

UploadAsync(Stream, BlobHttpHeaders, IDictionary<String,String>, BlobRequestConditions, IProgress<Int64>, Nullable<AccessTier>, StorageTransferOptions, CancellationToken)

盡管在創建BlobServiceClient ,可以設置BlobClientOptions ,並且這些確實從抽象基類ClientOptions繼承了RetryOptions字段,但該字段是只讀的:

    // Summary:
    // Gets the client retry options.
    public RetryOptions Retry { get; }

如何使用Azure.Storage.Blobs程序集對 Azure blob 存儲操作設置重試策略?

創建 Blob 客戶端時應指定重試部分。 這是一個示例:

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

此外,可以在創建BlobClientOptions時設置BlobServiceClient

var blobServiceClient = new BlobServiceClient
(connectionString:storageAccountConnectionString, options: options );

然后,您可以使用BlobServiceClient.GetBlobContainerClient(blobContainerName:"")BlobContainerClient.GetBlobClient(blobName:"")以一致的方式使用選項構建 blob URI。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM