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?
Retry mechanismThe default policy retries with exponential backoff when Azure Search returns a 5xx or 408 (Request Timeout) response.
The minimum retention interval for a time-based retention policy is one day, and the maximum is 146,000 days (400 years).
Microsoft Entity Framework provides facilities for retrying database operations.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With