Show / Hide Table of Contents

Class RetryPolicy

Represents a policy that can be overriden to customize whether or not a request will be retried and how long to wait before retrying.

Inheritance
System.Object
HttpPipelinePolicy
RetryPolicy
Namespace: System.Dynamic.ExpandoObject
Assembly: Azure.Core.dll
Syntax
public class RetryPolicy : Azure.Core.Pipeline.HttpPipelinePolicy

Constructors

RetryPolicy(Int32, DelayStrategy)

Initializes a new instance of the RetryPolicy class.

Declaration
public RetryPolicy (int maxRetries = 3, Azure.Core.DelayStrategy delayStrategy = null);
Parameters
System.Int32 maxRetries

The maximum number of retries to attempt.

DelayStrategy delayStrategy

The delay to use for computing the interval between retry attempts.

Methods

OnRequestSent(HttpMessage)

This method can be overridden to introduce logic that runs after the request is sent through the pipeline and control is returned to the retry policy. This method will only be called for sync methods.

Declaration
protected internal virtual void OnRequestSent (Azure.Core.HttpMessage message);
Parameters
HttpMessage message

The message containing the request and response.

OnRequestSentAsync(HttpMessage)

This method can be overridden to introduce logic that runs after the request is sent through the pipeline and control is returned to the retry policy. This method will only be called for async methods.

Declaration
protected internal virtual System.Threading.Tasks.ValueTask OnRequestSentAsync (Azure.Core.HttpMessage message);
Parameters
HttpMessage message

The message containing the request and response.

Returns
System.Threading.Tasks.ValueTask

OnSendingRequest(HttpMessage)

This method can be overridden to introduce logic before each request attempt is sent. This will run even for the first attempt. This method will only be called for sync methods.

Declaration
protected internal virtual void OnSendingRequest (Azure.Core.HttpMessage message);
Parameters
HttpMessage message

The message containing the request and response.

OnSendingRequestAsync(HttpMessage)

This method can be overriden to introduce logic that runs before the request is sent. This will run even for the first attempt. This method will only be called for async methods.

Declaration
protected internal virtual System.Threading.Tasks.ValueTask OnSendingRequestAsync (Azure.Core.HttpMessage message);
Parameters
HttpMessage message

The message containing the request and response.

Returns
System.Threading.Tasks.ValueTask

Process(HttpMessage, ReadOnlyMemory<HttpPipelinePolicy>)

This method can be overriden to take full control over the retry policy. If this is overriden and the base method isn't called, it is the implementer's responsibility to populate the ProcessingContext property. This method will only be called for sync methods.

Declaration
public override void Process (Azure.Core.HttpMessage message, ReadOnlyMemory<Azure.Core.Pipeline.HttpPipelinePolicy> pipeline);
Parameters
HttpMessage message

The HttpMessage this policy would be applied to.

System.ReadOnlyMemory<HttpPipelinePolicy> pipeline

The set of HttpPipelinePolicy to execute after current one.

ProcessAsync(HttpMessage, ReadOnlyMemory<HttpPipelinePolicy>)

This method can be overriden to take full control over the retry policy. If this is overriden and the base method isn't called, it is the implementer's responsibility to populate the ProcessingContext property. This method will only be called for async methods.

Declaration
public override System.Threading.Tasks.ValueTask ProcessAsync (Azure.Core.HttpMessage message, ReadOnlyMemory<Azure.Core.Pipeline.HttpPipelinePolicy> pipeline);
Parameters
HttpMessage message

The HttpMessage this policy would be applied to.

System.ReadOnlyMemory<HttpPipelinePolicy> pipeline

The set of HttpPipelinePolicy to execute after current one.

Returns
System.Threading.Tasks.ValueTask

The System.Threading.Tasks.ValueTask representing the asynchronous operation.

ShouldRetry(HttpMessage, Exception)

This method can be overriden to control whether a request should be retried. It will be called for any response where IsError is true, or if an exception is thrown from any subsequent pipeline policies or the transport. This method will only be called for sync methods.

Declaration
protected internal virtual bool ShouldRetry (Azure.Core.HttpMessage message, Exception exception);
Parameters
HttpMessage message

The message containing the request and response.

System.Exception exception

The exception that occurred, if any, which can be used to determine if a retry should occur.

Returns
System.Boolean

Whether or not to retry.

ShouldRetryAsync(HttpMessage, Exception)

This method can be overriden to control whether a request should be retried. It will be called for any response where IsError is true, or if an exception is thrown from any subsequent pipeline policies or the transport. This method will only be called for async methods.

Declaration
protected internal virtual System.Threading.Tasks.ValueTask<bool> ShouldRetryAsync (Azure.Core.HttpMessage message, Exception exception);
Parameters
HttpMessage message

The message containing the request and response.

System.Exception exception

The exception that occurred, if any, which can be used to determine if a retry should occur.

Returns
System.Threading.Tasks.ValueTask<System.Boolean>

Whether or not to retry.

Back to top Azure SDK for .NET