DynamicBackoffStrategy Class
- Namespace
- Kampute.HttpClient.RetryManagement
- Assembly
- Kampute.HttpClient.dll
Definition
Represents a factory that dynamically creates retry schedulers based on runtime conditions of HTTP requests.
public class DynamicBackoffStrategy : IHttpBackoffProvider- Inheritance
- object
- DynamicBackoffStrategy
- Implements
Remarks
Constructors
DynamicBackoffStrategy(Func<HttpRequestErrorContext, IRetryScheduler>)
Initializes a new instance of the DynamicBackoffStrategy with a scheduler factory function.
public DynamicBackoffStrategy(Func<HttpRequestErrorContext, IRetryScheduler> schedulerFactory)Parameters
schedulerFactoryFunc<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
schedulerFactoryisnull.
DynamicBackoffStrategy(Func<HttpRequestErrorContext, IRetryStrategy>)
Initializes a new instance of the DynamicBackoffStrategy with a strategy factory function.
public DynamicBackoffStrategy(Func<HttpRequestErrorContext, IRetryStrategy> strategyFactory)Parameters
strategyFactoryFunc<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
strategyFactoryisnull.
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
ctxHttpRequestErrorContext- 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
ctxisnull. - InvalidOperationException
- Thrown if the scheduler factory function returns
null.

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.