Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

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)

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

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

like image 892
Jude Fisher Avatar asked Mar 04 '20 19:03

Jude Fisher


People also ask

What is retry policy in Azure?

Retry mechanismThe default policy retries with exponential backoff when Azure Search returns a 5xx or 408 (Request Timeout) response.

What is retention policy in Azure blob storage?

The minimum retention interval for a time-based retention policy is one day, and the maximum is 146,000 days (400 years).

What is the name of the Microsoft retry framework?

Microsoft Entity Framework provides facilities for retrying database operations.


1 Answers

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

In addition, it is possible to set the BlobClientOptions when creating a BlobServiceClient:

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

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

like image 75
Thiago Custodio Avatar answered Sep 18 '22 13:09

Thiago Custodio