Carubbi.ResilientFlurl
1.5.0
See the version list below for details.
dotnet add package Carubbi.ResilientFlurl --version 1.5.0
NuGet\Install-Package Carubbi.ResilientFlurl -Version 1.5.0
<PackageReference Include="Carubbi.ResilientFlurl" Version="1.5.0" />
paket add Carubbi.ResilientFlurl --version 1.5.0
#r "nuget: Carubbi.ResilientFlurl, 1.5.0"
// Install Carubbi.ResilientFlurl as a Cake Addin #addin nuget:?package=Carubbi.ResilientFlurl&version=1.5.0 // Install Carubbi.ResilientFlurl as a Cake Tool #tool nuget:?package=Carubbi.ResilientFlurl&version=1.5.0
Carubbi.ResilientFlurl
Overview
Carubbi.ResilientFlurl is a library designed to enhance resilience in HTTP client communications within your .NET applications. It simplifies the setup of resilient HTTP clients by providing a straightforward way to configure standard and custom resilience pipelines using policies such as Retry, Circuit Breaker, Concurrency Limiter, and Timeout. Additionally, it integrates with FlurlClient to provide enhanced capabilities for HTTP requests.
Getting Started
Installation
- Install the
Carubbi.ResilientFlurl
NuGet package in your project:Install-Package Carubbi.ResilientFlurl
- Install the
Setup
- In your project's startup or configuration class (e.g.,
Startup.cs
in a typical ASP.NET Core application), add resilient HTTP clients using theAddResilientHttpClient
method provided byCarubbi.ResilientFlurl
. For each client class you want to configure, call:
Replacebuilder.Services.AddResilientHttpClient<ClientA>(configuration); builder.Services.AddResilientHttpClient<ClientB>(configuration);
ClientA
andClientB
with the actual client classes you have in your project.
- In your project's startup or configuration class (e.g.,
Configuration
- Configure the pipeline policies for each client in the
appsettings.json
file under respective client names (ClientA
,ClientB
, etc.):{ "ClientA": { "HttpClient": { "BaseAddress": "https://localhost:7277/", "UseStandardResiliencePipeline": true } }, "ClientB": { "HttpClient": { "BaseAddress": "https://localhost:7276/", "CustomResiliencePipeline": [ { "Policy": "ConcurrencyLimiter", "Parameters": { "MaxConcurrentCalls": 10 } }, { "Policy": "Timeout", "Parameters": { "TimeoutInSeconds": 15 } }, { "Policy": "Retry", "Parameters": { "MaxAttempts": 10, "DelayInSeconds": 2 } }, { "Policy": "CircuitBreaker", "Parameters": { "DurationInSeconds": 30, "SamplingDurationInSeconds": 60, "FailureRatio": 50, "MinimumThroughput": 1000 } } ] } } }
- Configure the pipeline policies for each client in the
Usage
- After setup, inject the configured
HttpClient
instances into your services or controllers using theIHttpClientFactory
. TheCarubbi.ResilientFlurl
library will handle the resilience policies based on the configurations provided. - Additionally, each configured
HttpClient
includes an associatedFlurlClient
, allowing you to leverage Flurl's fluent interface for making HTTP requests.
- After setup, inject the configured
Configuration Details
- BaseAddress: Specifies the base URL for the HTTP client.
- UseStandardResiliencePipeline: If set to
true
, uses the standard resilience pipeline which includes default policies. - CustomResiliencePipeline: Allows defining a custom set of resilience policies for fine-grained control over retries, timeouts, concurrency limits, and circuit breaking.
- Policies available:
- Retry: Retries failed requests according to specified parameters (
MaxAttempts
,DelayInSeconds
). - Timeout: Sets a maximum time duration for requests (
TimeoutInSeconds
). - ConcurrencyLimiter: Limits concurrent requests (
MaxConcurrentCalls
). - CircuitBreaker: Prevents requests from being sent to a service that is likely to fail (
DurationInSeconds
,SamplingDurationInSeconds
,FailureRatio
,MinimumThroughput
).
- Retry: Retries failed requests according to specified parameters (
- Policies available:
Additional Notes
- Ensure that the
appsettings.json
file is correctly structured and that policies are configured appropriately for each client. - You can mix and match standard and custom resilience pipelines across different clients in your application based on their specific needs.
License
This library is licensed under the MIT License. See the LICENSE file for more details.
For more information and updates, visit the Carubbi.ResilientFlurl GitHub repository.
For usage example check the demo repository
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net8.0 is compatible. 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. |
-
net8.0
- Flurl.Http (>= 4.0.2)
- Microsoft.Extensions.Http.Resilience (>= 8.6.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.