Quantcast
Channel: Active questions tagged retry-logic - Stack Overflow
Viewing all articles
Browse latest Browse all 950

How to configure the Rate Limiter of the StandardResilienceHandler

$
0
0

I'm writing an application that connects to another HTTP service. I want to rate-limit my outgoing requests to that external service.

Ideally, I want to use the standard resilience handler as documented here, to benefit from the configured best-practice defaults when it comes to resiliency.

services.AddHttpClient<ExternalServiceGateway>()    .AddStandardResilienceHandler();

However, since I know that the external service is rate-limited to 120 req/sec, I want to apply a similar policy to my outgoing calls.

I can achieve this using a separately-configured ResiliencePipeline (see below), but I want to combine this with the AddStandardResilienceHandler(). Is there any way to achieve this?

var pipeline = new ResiliencePipelineBuilder()    .AddRetry(new RetryStrategyOptions    {        ShouldHandle = new PredicateBuilder().Handle<RateLimiterRejectedException>(),        Delay = TimeSpan.FromSeconds(1),        MaxRetryAttempts = 5,        BackoffType = DelayBackoffType.Exponential,        UseJitter = true    })    .AddRateLimiter(new FixedWindowRateLimiter(new FixedWindowRateLimiterOptions()    {       PermitLimit = 2,       Window = TimeSpan.FromSeconds(1)    }))    .Build();

Update: example code for problem/solution

I have published a minimal solution to experiment with this problem/solution here.


Viewing all articles
Browse latest Browse all 950


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>