Quantcast
Channel: Active questions tagged retry-logic - Stack Overflow
Viewing all articles
Browse latest Browse all 950

grpc-dotnet retry with Polly even if connection could not be established (HttpMessageHandler is not called)

$
0
0

Why is not called Polly policy http message handler when connection could not be established?I would like to retry even if connection could not be established, the service might be restarting when I'm doing the grpc call.

How can I add http message handler which will be called even during connection?

serviceCollection    .AddGrpcClient<TGrpcClientType>(option =>    {        option.Address = new Uri(configuration.EndpointAddress);        option.CallOptionsActions.Add(ctx =>            ctx.CallOptions = ctx.CallOptions                .WithDeadline(DateTime.UtcNow.Add(configuration.Deadline)));    })    .AddPolicyHandler(retryFunc);      

This sample code was taken from past discussion https://github.com/grpc/grpc-dotnet/issues/686

Func<HttpRequestMessage, IAsyncPolicy<HttpResponseMessage>> retryFunc = (request) =>{    return Policy.HandleResult<HttpResponseMessage>(r => r.Headers.GetValues("grpc-status").FirstOrDefault() != "0")        .WaitAndRetryAsync(3, (input) => TimeSpan.FromSeconds(3 + input), (result, timeSpan, retryCount, context) =>        {            var grpcStatus = (StatusCode)int.Parse(result.Result.Headers.GetValues("grpc-status").FirstOrDefault() ?? "0");            Console.WriteLine($"Request failed with {grpcStatus}. Retry.");        });};    

Link to grpc-dotnet issue


Viewing all articles
Browse latest Browse all 950

Trending Articles