Incendium.RetryPolicy
1.0.4
dotnet add package Incendium.RetryPolicy --version 1.0.4
NuGet\Install-Package Incendium.RetryPolicy -Version 1.0.4
<PackageReference Include="Incendium.RetryPolicy" Version="1.0.4" />
paket add Incendium.RetryPolicy --version 1.0.4
#r "nuget: Incendium.RetryPolicy, 1.0.4"
// Install Incendium.RetryPolicy as a Cake Addin #addin nuget:?package=Incendium.RetryPolicy&version=1.0.4 // Install Incendium.RetryPolicy as a Cake Tool #tool nuget:?package=Incendium.RetryPolicy&version=1.0.4
Incendium.RetryPolicy
Incendium.RetryPolicy is a lightweight .NET standard 2.1 library that provides robust HTTP request retry functionality and rate limiting capabilities through two main components:
RetryHttpClientHandler
: Handles automatic retry of failed HTTP requestsRateGate
: Manages rate limiting for your API calls
Installation
Using Package Manager:
PM> Install-Package Incendium.RetryPolicy
Using .NET CLI:
dotnet add package Incendium.RetryPolicy
Usage
RetryHttpClientHandler
The handler automatically retries requests in the following scenarios:
- Network exceptions (
HttpRequestException
) - Server errors (5xx status codes)
- Request timeout (408)
- Rate limit exceeded (429)
Basic setup:
var handler = new RetryHttpClientHandler(new HttpClientHandler())
{
RetryCount = 5, // sets 5 retry attempts
RetryOnHttpRequestException = true, // sets the retry flag in case of an HttpRequestException
FirstRetryDelay = TimeSpan.FromMilliseconds(100), // sets the median starting delay between requests
}
var client = new HttpClient(handler);
Rate Limiting
Integrate rate limiting using RateGate
:
var handler = new RetryHttpClientHandler(new HttpClientHandler())
{
RateGate = new RateGate(
occurrences: 10, // Maximum requests
timeUnit: TimeSpan.FromSeconds(60) // Time window
)
};
Retry Delay Strategies
The library provides three built-in delay strategies:
- Constant Delay
handler.RetryDelaysFactory = () => Delays.Constant(
delay: TimeSpan.FromSeconds(1),
count: 5
);
- Exponential Backoff
handler.RetryDelaysFactory = () => Delays.Exponential(
firstDelay: TimeSpan.FromMilliseconds(100),
count: 5
);
- DecorrelatedJitterBackoffV2 (Default)
handler.RetryDelaysFactory = () => Delays.DecorrelatedJitterBackoffV2(
firstDelay: TimeSpan.FromMilliseconds(100),
count: 5
);
You can also implement custom delay strategies by providing your own IEnumerable<TimeSpan>
through the RetryDelaysFactory
property.
License
This project is licensed under the MIT License - see the LICENSE file for details.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. |
.NET Core | netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.1 is compatible. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen60 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.1
- No dependencies.
NuGet packages (1)
Showing the top 1 NuGet packages that depend on Incendium.RetryPolicy:
Package | Downloads |
---|---|
Revelium.Evm
Revelium.Evm is .NET integration library for Etherlink and EVM-compatible networks |
GitHub repositories
This package is not used by any popular GitHub repositories.