Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sample on how to use with Polly #32

Open
sommmen opened this issue Sep 14, 2021 · 0 comments
Open

Sample on how to use with Polly #32

sommmen opened this issue Sep 14, 2021 · 0 comments

Comments

@sommmen
Copy link

sommmen commented Sep 14, 2021

Hiya,

I have a polly policy declared for my httpclient, I could do with a sample on how to get both polly and RateLimiter to play nice with eachother.

services.AddHttpClient<MyHttpClient>()
                .SetHandlerLifetime(TimeSpan.FromMinutes(5))
                .AddPolicyHandler((serviceProvider, _) => 
                    HttpPolicyExtensions.HandleTransientHttpError()
                        .WaitAndRetryAsync(Backoff.DecorrelatedJitterBackoffV2(TimeSpan.FromSeconds(1), 5),
                            (outcome, delay, i, _) =>
                            {
                                var logger = serviceProvider.GetService<ILogger<MyHttpClient>>();
                                if (logger != null)
                                {
                                    if (outcome.Exception != null)
                                    {
                                        logger.LogError(outcome.Exception, "Delaying {Delay}, then making retry {Retry}. Result: {Result}", delay, i, outcome.Result);
                                    }
                                    else
                                    {
                                        logger.LogWarning("Delaying {Delay}, then making retry {Retry}. Result: {Result}", delay, i, outcome.Result);
                                    }
                                }
                            })
                );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant