polly

Adding Polly retry policy to a mocked HttpClient?

…衆ロ難τιáo~ 提交于 2020-04-17 22:48:42
问题 So I have to use a library that takes a HttpClient, and may throw a throttling exception in case of a 429 response from the remote system. I'd like to test a Polly policy that would back off for the requested amount of seconds, but I can't figure out how to modify the test to add a Polly policy. I looked at this SO question, but my circumstances are different: Testing Polly retry policy with moq Here's the test that verifies the exception is thrown. I would like to make a different version

Adding Polly retry policy to a mocked HttpClient?

旧街凉风 提交于 2020-04-17 22:44:40
问题 So I have to use a library that takes a HttpClient, and may throw a throttling exception in case of a 429 response from the remote system. I'd like to test a Polly policy that would back off for the requested amount of seconds, but I can't figure out how to modify the test to add a Polly policy. I looked at this SO question, but my circumstances are different: Testing Polly retry policy with moq Here's the test that verifies the exception is thrown. I would like to make a different version

Adding Polly retry policy to a mocked HttpClient?

*爱你&永不变心* 提交于 2020-04-17 22:43:45
问题 So I have to use a library that takes a HttpClient, and may throw a throttling exception in case of a 429 response from the remote system. I'd like to test a Polly policy that would back off for the requested amount of seconds, but I can't figure out how to modify the test to add a Polly policy. I looked at this SO question, but my circumstances are different: Testing Polly retry policy with moq Here's the test that verifies the exception is thrown. I would like to make a different version

What to return as onRetryAsync?

心不动则不痛 提交于 2020-04-17 18:07:16
问题 I am trying to implement a retry policy that will retry if an exception is thrown. Unfortunately I can't seem to get the signature for the onRetryAsync block right. The compiler says "Not all code paths return a value in lambda expression of type...." The documentation suggests to return Task.CompletedTask but that's apparently not available to me in the current libraries I am forced to use. var retryPolicy = Policy .Handle<SigsThrottledException>(e => e.RetryAfterInSeconds > 0)

What to return as onRetryAsync?

会有一股神秘感。 提交于 2020-04-17 17:56:09
问题 I am trying to implement a retry policy that will retry if an exception is thrown. Unfortunately I can't seem to get the signature for the onRetryAsync block right. The compiler says "Not all code paths return a value in lambda expression of type...." The documentation suggests to return Task.CompletedTask but that's apparently not available to me in the current libraries I am forced to use. var retryPolicy = Policy .Handle<SigsThrottledException>(e => e.RetryAfterInSeconds > 0)

.Net微服务实践(四)[网关]:Ocelot限流熔断、缓存以及负载均衡

半城伤御伤魂 提交于 2020-04-13 13:46:36
【今日推荐】:为什么一到面试就懵逼!>>> 目录 限流 熔断 缓存 Header转化 HTTP方法转换 负载均衡 注入/重写中间件 后台管理 最后 在上篇 .Net微服务实践(三)[网关]:Ocelot配置路由和请求聚合 中我们介绍了Ocelot的配置,主要特性路由以及服务聚合。接下来,我们会介绍Ocelot的限流、熔断、缓存以及负载均衡。 限流 我们先来看限流的配置 Reroute节点中的配置如下: { "DownstreamPathTemplate": "/api/orders", "DownstreamScheme": "http", "DownstreamHostAndPorts": [ { "Host": "localhost", "Port": 5001 } ], "UpstreamPathTemplate": "/api/orders", "UpstreamHttpMethod": [ "Get" ], "RateLimitOptions": { "ClientWhitelist": [], "EnableRateLimiting": true, "Period": "10m", "PeriodTimespan": 3, "Limit": 1 } } GlobalConfiguration中的配置如下: "GlobalConfiguration": {

Polly Circuit breaker not maintaining state with .net core HTTP Client

余生长醉 提交于 2020-03-26 03:52:11
问题 I have implemented the polly retry and Circuit breaker policy (wrapped). when the call fails and the circuit is open for the previous call the next call again goes to the retry and hit the circuit breaker again instead of just throwing the circuitbreakexception. I think somehow the HTTP client is getting recreated again even though am using the typed client. I am not able to figure the issue. Here is the code Startup public void ConfigureServices(IServiceCollection services) { services.AddMvc

Refresh Token using Polly with Typed Client

穿精又带淫゛_ 提交于 2020-03-23 08:11:46
问题 I have a Typed Client which i have configured in the services and i am using Polly to make retries for transient faults. Aim: I want to make use of Polly to implement refresh token, whenever there is a 401 response from the target site, i want Polly to refresh the token and continue the initial request again. The problem is the typed client has all the api methods and the refresh token method, when the request is initiated from the typed client how do i access the typed client again to call

Refresh Token using Polly with Typed Client

两盒软妹~` 提交于 2020-03-23 08:11:44
问题 I have a Typed Client which i have configured in the services and i am using Polly to make retries for transient faults. Aim: I want to make use of Polly to implement refresh token, whenever there is a 401 response from the target site, i want Polly to refresh the token and continue the initial request again. The problem is the typed client has all the api methods and the refresh token method, when the request is initiated from the typed client how do i access the typed client again to call

Polly WaitAndRetryAsync hangs after one retry

假如想象 提交于 2020-02-06 02:41:38
问题 I'm using Polly in very basic scenario to do exponential backoff if an HTTP call fails: protected override async Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken) { return await HandleTransientHttpError() .Or<TimeoutException>() .WaitAndRetryAsync(4, retryAttempt => TimeSpan.FromSeconds(Math.Pow(3, retryAttempt))) .ExecuteAsync(async () => await base.SendAsync(request, cancellationToken).ConfigureAwait(false)); } private static PolicyBuilder