且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何使用Azure.Storage.Blobs程序集在Azure Blob存储操作上设置重试策略?

更新时间:2023-02-14 21:01:21

在创建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: blobClientOptions);

然后,您可以使用 BlobServiceClient.GetBlobContainerClient(blobContainerName:") BlobContainerClient.GetBlobClient(blobName:")以一致的方式构建Blob URI,带有选项.

You can then use BlobServiceClient.GetBlobContainerClient(blobContainerName:"") and BlobContainerClient.GetBlobClient(blobName:"") to build the blob URI in a consistent manner, with options.