嗨,我想暗示波利重试瞬态错误处理我很有趣,但重试对我不起作用,请让我知道我错在哪里。
var retryPolicy = Policy
.HandleResult<HttpResponseMessage>(r => r.StatusCode == HttpStatusCode.Unauthorized
|| r.StatusCode == HttpStatusCode.GatewayTimeout
|| r.StatusCode == HttpStatusCode.RequestTimeout
|| r.StatusCode == HttpStatusCode.ServiceUnavailable)
.WaitAndRetry(3, i => TimeSpan.FromSeconds(2), (result, timeSpan, retryCount, context) =>
{
Console.WriteLine($"Request failed with {result.Result.StatusCode}. Waiting {timeSpan} before next retry. Retry attempt {retryCount}");
});
retryPolicy.Execute(() =>
{
response = FailedOperation();
return response;
});
private static HttpResponseMessage FailedOperation()
{
Console.WriteLine("Exception !!!!!");
throw new HttpResponseException(HttpStatusCode.GatewayTimeout);
}