Single HttpClient
with several circuit breaker
#1802
-
I'm using a single builder.Services
.AddHttpClient("Default")
.AddResilienceHandler("default", b =>
{
b.AddCircuitBreaker(new()
{
BreakDuration = TimeSpan.FromSeconds(5),
FailureRatio = 0.1,
MinimumThroughput = 100,
SamplingDuration = TimeSpan.FromSeconds(30),
});
}); Is there any way to have a different circuit breaker for each backend that is consumed (depending on the hostname for example)? Or would it be better to create different |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
Without a more complete example of exactly what you're doing, I would have thought that having a different HttpClient for each endpoint with their own circuit breaker would be the easiest way to go about things. |
Beta Was this translation helpful? Give feedback.
-
This will work with a slight modification to your sample: builder.Services
.AddHttpClient("Default")
.AddResilienceHandler("default", b =>
{
b.AddCircuitBreaker(new()
{
BreakDuration = TimeSpan.FromSeconds(5),
FailureRatio = 0.1,
MinimumThroughput = 100,
SamplingDuration = TimeSpan.FromSeconds(30),
});
})
.SelectPipelineByAuthority(); Notice the use of httpClient.GetAsync("https://A"); // creates and caches the pipeline with "https://A" key
httpClient.GetAsync("https://B"); // creates and caches the pipeline with "https://B" key |
Beta Was this translation helpful? Give feedback.
@joegoldman2
This will work with a slight modification to your sample:
Notice the use of
SelectPipelineByAuthority
. This tells the handler to cache the pipeline by authority (scheme + host + port) extracted from request message. Effectiv…