Raki
How to slow down my api call to a external service using polly
I came across this code and tried to implement but I believe only 10 calls are processed, Even if 50 calls made. Is that the expected behaviour.
var rateLimitPolicy = Policy.RateLimitAsync<HttpResponseMessage>(10, TimeSpan.FromSeconds(1));
services
.AddHttpClient < IContentfulManagementService, ContentfulManagementService > ((s, c) => {
c.BaseAddress = new Uri(managementApiURL);
c.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", managementApiKey);
c.Timeout = timeout;
})
.AddTransientHttpErrorPolicy(ErrorPolicy)
.AddPolicyHandler(timeoutPolicy).AddPolicyHandler(rateLimitPolicy);
7 replies
How to write retry policy in .net
So is this policy should be handled in the startup. I already have a retry policy has been added for timeout. I can't able to see the class ResiliencePipeline eventhough I have polly in my .net core. Seems like I have Microsoft.extension.http.polly. Is both are different.
services
.AddHttpClient<IContentfulManagementService, ContentfulManagementService>((s, c) =>
{
c.BaseAddress = new Uri(managementApiURL);
c.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", ManagementClientApiKey);
c.Timeout = timeout;
})
.AddTransientHttpErrorPolicy(ErrorPolicy)
.AddPolicyHandler(timeoutPolicy);
private static Func<PolicyBuilder<HttpResponseMessage>, IAsyncPolicy<HttpResponseMessage>> ErrorPolicy =>
p => p.Or<TimeoutRejectedException>().WaitAndRetryAsync(2, retryAttempt => TimeSpan.FromSeconds(Math.Pow(2, retryAttempt)));
7 replies