Browse Source

add polly for grpc calls

features/migration-dotnet3
ericuss 5 years ago
parent
commit
bcb0455d1a
2 changed files with 22 additions and 4 deletions
  1. +11
    -2
      src/ApiGateways/Mobile.Bff.Shopping/aggregator/Services/GrpcCallerService.cs
  2. +11
    -2
      src/ApiGateways/Web.Bff.Shopping/aggregator/Services/GrpcCallerService.cs

+ 11
- 2
src/ApiGateways/Mobile.Bff.Shopping/aggregator/Services/GrpcCallerService.cs View File

@ -3,6 +3,7 @@ using System.Threading.Tasks;
using System;
using Grpc.Core;
using Serilog;
using Polly;
namespace Microsoft.eShopOnContainers.Mobile.Shopping.HttpAggregator.Services
{
@ -27,7 +28,11 @@ namespace Microsoft.eShopOnContainers.Mobile.Shopping.HttpAggregator.Services
try
{
return await func(httpClient);
return await Policy
.Handle<Exception>(ex => true)
.WaitAndRetryAsync(5, retryAttempt => TimeSpan.FromSeconds(Math.Pow(2, retryAttempt)), (e, t) => Log.Warning("Retrying the call to urlGrpc ={@urlGrpc}, BaseAddress={@BaseAddress}, errorMessage={@message}", urlGrpc, httpClient.BaseAddress,e.Message))
.ExecuteAsync(() => func(httpClient))
;
}
catch (RpcException e)
{
@ -59,7 +64,11 @@ namespace Microsoft.eShopOnContainers.Mobile.Shopping.HttpAggregator.Services
try
{
await func(httpClient);
await Policy
.Handle<Exception>(ex => true)
.WaitAndRetryAsync(5, retryAttempt => TimeSpan.FromSeconds(Math.Pow(2, retryAttempt)), (e, t) => Log.Warning("Retrying the call to urlGrpc ={@urlGrpc}, BaseAddress={@BaseAddress}, errorMessage={@message}", urlGrpc, httpClient.BaseAddress, e.Message))
.ExecuteAsync(() => func(httpClient))
;
}
catch (RpcException e)
{


+ 11
- 2
src/ApiGateways/Web.Bff.Shopping/aggregator/Services/GrpcCallerService.cs View File

@ -3,6 +3,7 @@ using System.Threading.Tasks;
using System;
using Grpc.Core;
using Serilog;
using Polly;
namespace Microsoft.eShopOnContainers.Web.Shopping.HttpAggregator.Services
{
@ -27,7 +28,11 @@ namespace Microsoft.eShopOnContainers.Web.Shopping.HttpAggregator.Services
try
{
return await func(httpClient);
return await Policy
.Handle<Exception>(ex => true)
.WaitAndRetryAsync(5, retryAttempt => TimeSpan.FromSeconds(Math.Pow(2, retryAttempt)), (e, t) => Log.Warning("Retrying the call to urlGrpc ={@urlGrpc}, BaseAddress={@BaseAddress}, errorMessage={@message}", urlGrpc, httpClient.BaseAddress, e.Message))
.ExecuteAsync(() => func(httpClient))
;
}
catch (RpcException e)
{
@ -59,7 +64,11 @@ namespace Microsoft.eShopOnContainers.Web.Shopping.HttpAggregator.Services
try
{
await func(httpClient);
await Policy
.Handle<Exception>(ex => true)
.WaitAndRetryAsync(5, retryAttempt => TimeSpan.FromSeconds(Math.Pow(2, retryAttempt)), (e, t) => Log.Warning("Retrying the call to urlGrpc ={@urlGrpc}, BaseAddress={@BaseAddress}, errorMessage={@message}", urlGrpc, httpClient.BaseAddress, e.Message))
.ExecuteAsync(() => func(httpClient))
;
}
catch (RpcException e)
{


Loading…
Cancel
Save