Table of Contents

Class DynamicBackoffStrategy

Namespace
Kampute.HttpClient.RetryManagement
Assembly
Kampute.HttpClient.dll

Represents a factory that dynamically creates retry schedulers based on runtime conditions of HTTP requests.

public class DynamicBackoffStrategy : IHttpBackoffProvider
Inheritance
DynamicBackoffStrategy
Implements
Inherited Members

Remarks

The DynamicBackoffStrategy class leverages a factory function to instantiate IRetryScheduler objects, enabling the selection of specific retry strategies tailored to the conditions observed during the execution of HTTP requests. The decision-making process utilizes detailed context provided by HttpRequestErrorContext, which includes information about the HTTP client, the request, and any encountered exceptions.

This dynamic approach allows for the implementation of sophisticated retry strategies that can adjust to varying error types and operational scenarios. It is especially beneficial in complex distributed systems where distinct error conditions or system states may necessitate different retry behaviors for optimizing overall system performance and reliability.

Constructors

DynamicBackoffStrategy(Func<HttpRequestErrorContext, IRetryScheduler>)

Initializes a new instance of the DynamicBackoffStrategy with a scheduler factory function.

public DynamicBackoffStrategy(Func<HttpRequestErrorContext, IRetryScheduler> schedulerFactory)

Parameters

schedulerFactory Func<HttpRequestErrorContext, IRetryScheduler>

A factory function that produces IRetryScheduler instances, allowing for dynamic selection of retry strategies based on the detailed context of failed HTTP requests.

Exceptions

ArgumentNullException

Thrown if schedulerFactory is null.

DynamicBackoffStrategy(Func<HttpRequestErrorContext, IRetryStrategy>)

Initializes a new instance of the DynamicBackoffStrategy with a strategy factory function.

public DynamicBackoffStrategy(Func<HttpRequestErrorContext, IRetryStrategy> strategyFactory)

Parameters

strategyFactory Func<HttpRequestErrorContext, IRetryStrategy>

A factory function that produces IRetryStrategy instances, allowing for dynamic selection of retry strategies based on the detailed context of failed HTTP requests.

Exceptions

ArgumentNullException

Thrown if strategyFactory is null.

Methods

CreateScheduler(HttpRequestErrorContext)

Creates a retry scheduler tailored to the specific conditions of a failed HTTP request, as determined by the provided context.

public IRetryScheduler CreateScheduler(HttpRequestErrorContext ctx)

Parameters

ctx HttpRequestErrorContext

The context containing detailed information about the failed HTTP request, such as the client, request, and error details.

Returns

IRetryScheduler

An instance of IRetryScheduler configured to manage retry attempts for the given request context.

Exceptions

ArgumentNullException

Thrown if ctx is null.

InvalidOperationException

Thrown if the scheduler factory function returns null.