相关疑难解决方法(0)

Polly (.Net) 默认重试哪些 HTTP 错误代码?

我知道我可以指定 HTTP 错误代码列表(例如 408、502、503 等),我想使用Polly重试,但是如果未指定,默认情况下将重试的这些代码的列表是什么?

.net polly

14
推荐指数
1
解决办法
1万
查看次数

哪些HTTP错误永远不会触发自动重试?

我正在尝试使一些微服务更具弹性,并且重试某些类型的HTTP请求将有助于此.

重试超时会给客户带来非常缓慢的体验,因此我不打算在这种情况下重试.重试400s无济于事,因为错误的请求在几毫秒后仍然是一个错误的请求.

我想还有其他原因不能重试一些其他类型的错误,但是哪些错误以及为什么?

http httpresponse spring-retry hystrix microservices

13
推荐指数
2
解决办法
4378
查看次数

如何在Flurl.Http上使用Polly?

目前我有这个要求:

await url
    .SetQueryParams(queryString)
    .SetClaimsToken()
    .GetJsonAsync<T>()
Run Code Online (Sandbox Code Playgroud)

我现在想开始使用Polly(https://github.com/App-vNext/Polly)来处理重试并提供更好的用户体验.例如,由于网络连接不良,第一次尝试时不会"挂断"用户.这是我尝试使用的示例:

int[] httpStatusCodesWorthRetrying = { 408, 500, 502, 503, 504 };
Policy
    .Handle<HttpException>()
    .OrResult<HttpResponse>(r => httpStatusCodesWorthRetrying.Contains(r.StatusCode))
    .WaitAndRetryAsync(new[] {
                    TimeSpan.FromSeconds(1),
                    TimeSpan.FromSeconds(2),
                    TimeSpan.FromSeconds(3)
                })
    .ExecuteAsync( await url... )
Run Code Online (Sandbox Code Playgroud)

但它需要HttpResponse是返回类型.正如你从我的Flurl例子中看到的那样,它正在返回T,即使它是一个HttpResponse.这T只是用于反序列化的类型StringContent.

第一个例子根本不起作用,因为我在PCL中使用它并且我无法获得对它的引用System.Web.所以我尝试了这个:

Policy
    .HandleResult(HttpStatusCode.InternalServerError)
    .OrResult(HttpStatusCode.BadGateway)
    .OrResult(HttpStatusCode.BadRequest)
    .WaitAndRetryAsync(new[] {
        TimeSpan.FromSeconds(1),
        TimeSpan.FromSeconds(2),
        TimeSpan.FromSeconds(3)
    })
    .ExecuteAsync(async () =>
    {
        await url...
    });
Run Code Online (Sandbox Code Playgroud)

但是这个也不起作用,因为Polly期望HttpStatusCode作为回归类型.所以我的问题是:我如何告诉polly处理那些HttpStatusCode并仍允许我返回类型T

c# httpresponse flurl polly

4
推荐指数
3
解决办法
2299
查看次数

标签 统计

httpresponse ×2

polly ×2

.net ×1

c# ×1

flurl ×1

http ×1

hystrix ×1

microservices ×1

spring-retry ×1