![]() |
VOOZH | about |
dotnet add package Dodo.HttpClient.ResiliencePolicies --version 2.1.0
NuGet\Install-Package Dodo.HttpClient.ResiliencePolicies -Version 2.1.0
<PackageReference Include="Dodo.HttpClient.ResiliencePolicies" Version="2.1.0" />
<PackageVersion Include="Dodo.HttpClient.ResiliencePolicies" Version="2.1.0" />Directory.Packages.props
<PackageReference Include="Dodo.HttpClient.ResiliencePolicies" />Project file
paket add Dodo.HttpClient.ResiliencePolicies --version 2.1.0
#r "nuget: Dodo.HttpClient.ResiliencePolicies, 2.1.0"
#:package Dodo.HttpClient.ResiliencePolicies@2.1.0
#addin nuget:?package=Dodo.HttpClient.ResiliencePolicies&version=2.1.0Install as a Cake Addin
#tool nuget:?package=Dodo.HttpClient.ResiliencePolicies&version=2.1.0Install as a Cake Tool
Dodo.HttpClient.ResiliencePolicies library extends IHttpClientBuilder with easy to use resilience policies for the HttpClient.
In the world of microservices it is quite important to pay attention to resilience of communications between services. You have to think about things like retries, timeouts, circuit breakers, etc. We already have a great library for this class of problems called Polly. It is really powerful. Polly is like a Swiss knife gives you a lot of functionality, but you should know how and when to use it. It could be a complicated task.
Main goal of our library is to hide this complexity from the end-users. It uses Polly under the hood and provides some pre-defined functionality with reasonable defaults and minimal settings to setup resilience policies atop of HttpClient. You can just plug the with single line of code and your HttpClient will become much more robust than before.
Library provides few methods which returns IHttpClientBuilder and you may chain it with other HttpMessageHandler.
There are list of public methods to use:
// Pre-defined policies with defaults settings
IHttpClientBuilder AddResiliencePolicies(this IHttpClientBuilder clientBuilder);
// Pre-defined policies with custom settings
IHttpClientBuilder AddResiliencePolicies(this IHttpClientBuilder clientBuilder, ResiliencePoliciesSettings settings)
AddResiliencePolicies wraps HttpClient with four policies:
Library also provides pre-configured HttpClient:
// Pre-defined HttpClientFactory which is configured to work with `application/json` MIME media type and uses default ResiliencePolicies
IHttpClientBuilder AddJsonClient<TClientInterface, TClientImplementation>(
this IServiceCollection sc,
Uri baseAddress,
string clientName = null)
// Pre-defined HttpClientFactory which is configured to work with `application/json` MIME media type and uses ResiliencePolicies with custom settings
IHttpClientBuilder AddJsonClient<TClientInterface, TClientImplementation>(
this IServiceCollection sc,
Uri baseAddress,
ResiliencePoliciesSettings settings,
string clientName = null)
Custom settings can be provided via ResiliencePoliciesSettings (see examples below).
Also you may check the provided by the library (all of this can be overriden in custom settings).
Using default client provided by the library and add it to the ServiceCollection in the Startup like this:
using Dodo.HttpClientResiliencePolicies;
...
service // IServiceCollection
.AddJsonClient(...) // HttpClientFactory to build JsonClient provided by the library with all defaults
Add resilience policies with default settings to existing HttpClient
using Dodo.HttpClientResiliencePolicies;
...
service // IServiceCollection
.AddHttpClient(...) // Existing HttpClientFactory
.AddResiliencePolicies() // Pre-defined resilience policies with all defaults
Define custom settings for resilience policies:
using Dodo.HttpClientResiliencePolicies;
...
var settings = new ResiliencePoliciesSettings
{
OverallTimeout = TimeSpan.FromSeconds(50),
TimeoutPerTry = TimeSpan.FromSeconds(2),
RetryPolicySettings = RetryPolicySettings.Jitter(2, TimeSpan.FromMilliseconds(50)),
CircuitBreakerPolicySettings = new CircuitBreakerPolicySettings(
failureThreshold: 0.5,
minimumThroughput: 10,
durationOfBreak: TimeSpan.FromSeconds(5),
samplingDuration: TimeSpan.FromSeconds(30)
),
OnRetry = (response, time) => { ... }, // Handle retry event. For example you may add logging here
OnBreak = (response, time) => { ... }, // Handle CircuitBreaker break event. For example you may add logging here
OnReset = () => {...}, // Handle CircuitBreaker reset event. For example you may add logging here
OnHalfOpen = () => {...}, // Handle CircuitBreaker reset event. For example you may add logging here
ExtraBreakCondition = BreakConditions.OnTooManyRequests // Extra condition for CircuitBreaker to open (opens on TooManyRequests by default)
}
You may provide only properties which you want to customize, the defaults will be used for the rest.
You may choose different retry strategies. RetryPolicySettings provides static methods to choose Constant, Linear, Exponential or Jitter (exponential with jitter backoff) strategies. Jitter is used as default strategy.
You may provide settings as a parameter to .AddJsonClient(...) or .AddResiliencePolicies() to override default settings.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net5.0 net5.0 is compatible. net5.0-windows net5.0-windows was computed. net6.0 net6.0 is compatible. net6.0-android net6.0-android was computed. net6.0-ios net6.0-ios was computed. net6.0-maccatalyst net6.0-maccatalyst was computed. net6.0-macos net6.0-macos was computed. net6.0-tvos net6.0-tvos was computed. net6.0-windows net6.0-windows was computed. net7.0 net7.0 was computed. net7.0-android net7.0-android was computed. net7.0-ios net7.0-ios was computed. net7.0-maccatalyst net7.0-maccatalyst was computed. net7.0-macos net7.0-macos was computed. net7.0-tvos net7.0-tvos was computed. net7.0-windows net7.0-windows was computed. net8.0 net8.0 was computed. net8.0-android net8.0-android was computed. net8.0-browser net8.0-browser was computed. net8.0-ios net8.0-ios was computed. net8.0-maccatalyst net8.0-maccatalyst was computed. net8.0-macos net8.0-macos was computed. net8.0-tvos net8.0-tvos was computed. net8.0-windows net8.0-windows was computed. net9.0 net9.0 was computed. net9.0-android net9.0-android was computed. net9.0-browser net9.0-browser was computed. net9.0-ios net9.0-ios was computed. net9.0-maccatalyst net9.0-maccatalyst was computed. net9.0-macos net9.0-macos was computed. net9.0-tvos net9.0-tvos was computed. net9.0-windows net9.0-windows was computed. net10.0 net10.0 was computed. net10.0-android net10.0-android was computed. net10.0-browser net10.0-browser was computed. net10.0-ios net10.0-ios was computed. net10.0-maccatalyst net10.0-maccatalyst was computed. net10.0-macos net10.0-macos was computed. net10.0-tvos net10.0-tvos was computed. net10.0-windows net10.0-windows was computed. |
| .NET Core | netcoreapp2.0 netcoreapp2.0 was computed. netcoreapp2.1 netcoreapp2.1 was computed. netcoreapp2.2 netcoreapp2.2 was computed. netcoreapp3.0 netcoreapp3.0 was computed. netcoreapp3.1 netcoreapp3.1 is compatible. |
| .NET Standard | netstandard2.0 netstandard2.0 is compatible. netstandard2.1 netstandard2.1 was computed. |
| .NET Framework | net461 net461 was computed. net462 net462 was computed. net463 net463 was computed. net47 net47 was computed. net471 net471 was computed. net472 net472 was computed. net48 net48 was computed. net481 net481 was computed. |
| MonoAndroid | monoandroid monoandroid was computed. |
| MonoMac | monomac monomac was computed. |
| MonoTouch | monotouch monotouch was computed. |
| Tizen | tizen40 tizen40 was computed. tizen60 tizen60 was computed. |
| Xamarin.iOS | xamarinios xamarinios was computed. |
| Xamarin.Mac | xamarinmac xamarinmac was computed. |
| Xamarin.TVOS | xamarintvos xamarintvos was computed. |
| Xamarin.WatchOS | xamarinwatchos xamarinwatchos was computed. |
This package is not used by any NuGet packages.
This package is not used by any popular GitHub repositories.