Show / Hide Table of Contents

Class ClientRetryPolicy

A PipelinePolicy used by a ClientPipeline to decide whether or not to retry a PipelineRequest.

Inheritance
System.Object
PipelinePolicy
ClientRetryPolicy
Namespace: System.Dynamic.ExpandoObject
Assembly: System.ClientModel.dll
Syntax
[System.Runtime.CompilerServices.Nullable(0)]
[System.Runtime.CompilerServices.NullableContext(1)]
public class ClientRetryPolicy : System.ClientModel.Primitives.PipelinePolicy

Constructors

ClientRetryPolicy(Int32)

Creates a new instance of the ClientRetryPolicy class.

Declaration
public ClientRetryPolicy (int maxRetries = 3);
Parameters
System.Int32 maxRetries

The maximum number of retries to attempt.

ClientRetryPolicy(Int32, Boolean, ILoggerFactory)

Creates a new instance of the ClientRetryPolicy class.

Declaration
[System.Runtime.CompilerServices.NullableContext(2)]
public ClientRetryPolicy (int maxRetries, bool enableLogging, Microsoft.Extensions.Logging.ILoggerFactory loggerFactory);
Parameters
System.Int32 maxRetries

The maximum number of retries to attempt.

System.Boolean enableLogging

If client-wide logging is enabled for this pipeline.

Microsoft.Extensions.Logging.ILoggerFactory loggerFactory

The Microsoft.Extensions.Logging.ILoggerFactory to use to create an Microsoft.Extensions.Logging.ILogger instance for logging. If one is not provided, logs are written to Event Source by default.

Properties

Default

The ClientRetryPolicy instance used by a default ClientPipeline.

Declaration
public static System.ClientModel.Primitives.ClientRetryPolicy Default { get; }
Property Value
ClientRetryPolicy

Methods

GetNextDelay(PipelineMessage, Int32)

A method that can be overridden by derived types to customize the default ClientRetryPolicy logic. It is called from Process(PipelineMessage, IReadOnlyList<PipelinePolicy>, Int32) to determine how long the policy should wait before re-sending the request.

Declaration
protected virtual TimeSpan GetNextDelay (System.ClientModel.Primitives.PipelineMessage message, int tryCount);
Parameters
PipelineMessage message

The PipelineMessage for this pipeline invocation.

System.Int32 tryCount

A number indicating how many times the policy has tried to send the request.

Returns
System.TimeSpan

The amount of time to wait before the next retry attempt.

OnRequestSent(PipelineMessage)

A method that can be overridden by derived types to extend the default ClientRetryPolicy logic. It is called from Process(PipelineMessage, IReadOnlyList<PipelinePolicy>, Int32) just after control has been returned from the policy at the position after the retry policy in the pipeline.

Declaration
protected virtual void OnRequestSent (System.ClientModel.Primitives.PipelineMessage message);
Parameters
PipelineMessage message

The PipelineMessage containing the PipelineResponse that was received from the service.

OnRequestSentAsync(PipelineMessage)

A method that can be overridden by derived types to extend the default ClientRetryPolicy logic. It is called from Process(PipelineMessage, IReadOnlyList<PipelinePolicy>, Int32) just after control has been returned from the policy at the position after the retry policy in the pipeline.

Declaration
protected virtual System.Threading.Tasks.ValueTask OnRequestSentAsync (System.ClientModel.Primitives.PipelineMessage message);
Parameters
PipelineMessage message

The PipelineMessage containing the PipelineResponse that was received from the service.

Returns
System.Threading.Tasks.ValueTask

OnSendingRequest(PipelineMessage)

A method that can be overridden by derived types to extend the default ClientRetryPolicy logic. It is called from Process(PipelineMessage, IReadOnlyList<PipelinePolicy>, Int32) prior to passing control to the next policy in the pipeline.

Declaration
protected virtual void OnSendingRequest (System.ClientModel.Primitives.PipelineMessage message);
Parameters
PipelineMessage message

The PipelineMessage containing the PipelineRequest to be sent to the service.

OnSendingRequestAsync(PipelineMessage)

A method that can be overridden by derived types to extend the default ClientRetryPolicy logic. It is called from Process(PipelineMessage, IReadOnlyList<PipelinePolicy>, Int32) prior to passing control to the next policy in the pipeline.

Declaration
protected virtual System.Threading.Tasks.ValueTask OnSendingRequestAsync (System.ClientModel.Primitives.PipelineMessage message);
Parameters
PipelineMessage message

The PipelineMessage containing the PipelineRequest to be sent to the service.

Returns
System.Threading.Tasks.ValueTask

OnTryComplete(PipelineMessage)

A method that can be overridden by derived types to extend the default ClientRetryPolicy logic. It is called from Process(PipelineMessage, IReadOnlyList<PipelinePolicy>, Int32) after the time interval for the current retry attempt has passed.

Declaration
protected virtual void OnTryComplete (System.ClientModel.Primitives.PipelineMessage message);
Parameters
PipelineMessage message

The PipelineMessage for this pipeline invocation.

Process(PipelineMessage, IReadOnlyList<PipelinePolicy>, Int32)

Process the provided PipelineMessage according to the intended purpose of this PipelinePolicyinstance. Derived types must pass control to the next PipelinePolicy in the pipeline by calling ProcessNext(PipelineMessage, IReadOnlyList<PipelinePolicy>, Int32).

Declaration
public override sealed void Process (System.ClientModel.Primitives.PipelineMessage message, System.Collections.Generic.IReadOnlyList<System.ClientModel.Primitives.PipelinePolicy> pipeline, int currentIndex);
Parameters
PipelineMessage message

The PipelineMessage to process.

System.Collections.Generic.IReadOnlyList<PipelinePolicy> pipeline

The collection of PipelinePolicy instances in the ClientPipeline instance whose Send(PipelineMessage) method was called to invoke this method.

System.Int32 currentIndex

The index of this policy in the pipeline policy list. This value should be passed to ProcessNext(PipelineMessage, IReadOnlyList<PipelinePolicy>, Int32) to pass control to the next policy in the pipeline.

ProcessAsync(PipelineMessage, IReadOnlyList<PipelinePolicy>, Int32)

Process the provided PipelineMessage according to the intended purpose of this PipelinePolicyinstance. Derived types must pass control to the next PipelinePolicy in the pipeline by calling ProcessNextAsync(PipelineMessage, IReadOnlyList<PipelinePolicy>, Int32).

Declaration
[System.Diagnostics.DebuggerStepThrough]
public override sealed System.Threading.Tasks.ValueTask ProcessAsync (System.ClientModel.Primitives.PipelineMessage message, System.Collections.Generic.IReadOnlyList<System.ClientModel.Primitives.PipelinePolicy> pipeline, int currentIndex);
Parameters
PipelineMessage message

The PipelineMessage to process.

System.Collections.Generic.IReadOnlyList<PipelinePolicy> pipeline

The collection of PipelinePolicy instances in the ClientPipeline instance whose SendAsync(PipelineMessage) method was called to invoke this method.

System.Int32 currentIndex

The index of this policy in the pipeline policy list. This value should be passed to ProcessNextAsync(PipelineMessage, IReadOnlyList<PipelinePolicy>, Int32) to pass control to the next policy in the pipeline.

Returns
System.Threading.Tasks.ValueTask

ShouldRetry(PipelineMessage, Exception)

A method that can be overridden by derived types to customize the default ClientRetryPolicy logic. It is called from Process(PipelineMessage, IReadOnlyList<PipelinePolicy>, Int32) after control has been returned from the policy at the position after the retry policy in the pipeline.

Declaration
protected virtual bool ShouldRetry (System.ClientModel.Primitives.PipelineMessage message, Exception exception);
Parameters
PipelineMessage message

The PipelineMessage for this pipeline invocation.

System.Exception exception

The exception, if any, that was thrown from a policy after the retry policy in the pipeline.

Returns
System.Boolean

ShouldRetryAsync(PipelineMessage, Exception)

A method that can be overridden by derived types to customize the default ClientRetryPolicy logic. It is called from Process(PipelineMessage, IReadOnlyList<PipelinePolicy>, Int32) after control has been returned from the policy at the position after the retry policy in the pipeline.

Declaration
[System.Runtime.CompilerServices.NullableContext(0)]
protected virtual System.Threading.Tasks.ValueTask<bool> ShouldRetryAsync (System.ClientModel.Primitives.PipelineMessage message, Exception exception);
Parameters
PipelineMessage message

The PipelineMessage for this pipeline invocation.

System.Exception exception

The exception, if any, that was thrown from a policy after the retry policy in the pipeline.

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

Wait(TimeSpan, CancellationToken)

A method that can be overridden by derived types to customize the default ClientRetryPolicy logic. It is called from Process(PipelineMessage, IReadOnlyList<PipelinePolicy>, Int32) to wait the time interval returned by GetNextDelay(PipelineMessage, Int32).

Declaration
protected virtual void Wait (TimeSpan time, System.Threading.CancellationToken cancellationToken);
Parameters
System.TimeSpan time

The amount of time to wait before trying to send the request again.

System.Threading.CancellationToken cancellationToken

The System.Threading.CancellationToken used to cancel the wait if needed.

WaitAsync(TimeSpan, CancellationToken)

A method that can be overridden by derived types to customize the default ClientRetryPolicy logic. It is called from Process(PipelineMessage, IReadOnlyList<PipelinePolicy>, Int32) to wait the time interval returned by GetNextDelay(PipelineMessage, Int32).

Declaration
[System.Diagnostics.DebuggerStepThrough]
protected virtual System.Threading.Tasks.Task WaitAsync (TimeSpan time, System.Threading.CancellationToken cancellationToken);
Parameters
System.TimeSpan time

The amount of time to wait before trying to send the request again.

System.Threading.CancellationToken cancellationToken

The System.Threading.CancellationToken used to cancel the wait if needed.

Returns
System.Threading.Tasks.Task

A task that can be awaited to asynchronously delay before the next retry attempt.

Back to top Azure SDK for .NET