Browse Source

remove old grpc caller

pull/1559/head
Borja García Rodríguez 4 years ago
parent
commit
71eda6aeb9
2 changed files with 0 additions and 154 deletions
  1. +0
    -76
      src/ApiGateways/Mobile.Bff.Shopping/aggregator/Services/GrpcCallerService.cs
  2. +0
    -78
      src/ApiGateways/Web.Bff.Shopping/aggregator/Services/GrpcCallerService.cs

+ 0
- 76
src/ApiGateways/Mobile.Bff.Shopping/aggregator/Services/GrpcCallerService.cs View File

@ -1,76 +0,0 @@
using Grpc.Core;
using Grpc.Net.Client;
using Serilog;
using System;
using System.Threading.Tasks;
namespace Microsoft.eShopOnContainers.Mobile.Shopping.HttpAggregator.Services
{
public static class GrpcCallerService
{
public static async Task<TResponse> CallService<TResponse>(string urlGrpc, Func<GrpcChannel, Task<TResponse>> func)
{
AppContext.SetSwitch("System.Net.Http.SocketsHttpHandler.Http2UnencryptedSupport", true);
AppContext.SetSwitch("System.Net.Http.SocketsHttpHandler.Http2Support", true);
var channel = GrpcChannel.ForAddress(urlGrpc);
/*
using var httpClientHandler = new HttpClientHandler
{
ServerCertificateCustomValidationCallback = (message, cert, chain, errors) => { return true; }
};
*/
Log.Information("Creating grpc client base address urlGrpc ={@urlGrpc}, BaseAddress={@BaseAddress} ", urlGrpc, channel.Target);
try
{
return await func(channel);
}
catch (RpcException e)
{
Log.Error("Error calling via grpc: {Status} - {Message}", e.Status, e.Message);
return default;
}
finally
{
AppContext.SetSwitch("System.Net.Http.SocketsHttpHandler.Http2UnencryptedSupport", false);
AppContext.SetSwitch("System.Net.Http.SocketsHttpHandler.Http2Support", false);
}
}
public static async Task CallService(string urlGrpc, Func<GrpcChannel, Task> func)
{
AppContext.SetSwitch("System.Net.Http.SocketsHttpHandler.Http2UnencryptedSupport", true);
AppContext.SetSwitch("System.Net.Http.SocketsHttpHandler.Http2Support", true);
/*
using var httpClientHandler = new HttpClientHandler
{
ServerCertificateCustomValidationCallback = (message, cert, chain, errors) => { return true; }
};
*/
var channel = GrpcChannel.ForAddress(urlGrpc);
Log.Debug("Creating grpc client base address {@httpClient.BaseAddress} ", channel.Target);
try
{
await func(channel);
}
catch (RpcException e)
{
Log.Error("Error calling via grpc: {Status} - {Message}", e.Status, e.Message);
}
finally
{
AppContext.SetSwitch("System.Net.Http.SocketsHttpHandler.Http2UnencryptedSupport", false);
AppContext.SetSwitch("System.Net.Http.SocketsHttpHandler.Http2Support", false);
}
}
}
}

+ 0
- 78
src/ApiGateways/Web.Bff.Shopping/aggregator/Services/GrpcCallerService.cs View File

@ -1,78 +0,0 @@
using Grpc.Core;
using Grpc.Net.Client;
using Serilog;
using System;
using System.Threading.Tasks;
namespace Microsoft.eShopOnContainers.Web.Shopping.HttpAggregator.Services
{
public static class GrpcCallerService
{
public static async Task<TResponse> CallService<TResponse>(string urlGrpc, Func<GrpcChannel, Task<TResponse>> func)
{
AppContext.SetSwitch("System.Net.Http.SocketsHttpHandler.Http2UnencryptedSupport", true);
AppContext.SetSwitch("System.Net.Http.SocketsHttpHandler.Http2Support", true);
var channel = GrpcChannel.ForAddress(urlGrpc);
/*
using var httpClientHandler = new HttpClientHandler
{
ServerCertificateCustomValidationCallback = (message, cert, chain, errors) => { return true; }
};
*/
Log.Information("Creating grpc client base address urlGrpc ={@urlGrpc}, BaseAddress={@BaseAddress} ", urlGrpc, channel.Target);
try
{
return await func(channel);
}
catch (RpcException e)
{
Log.Error("Error calling via grpc: {Status} - {Message}", e.Status, e.Message);
return default;
}
finally
{
AppContext.SetSwitch("System.Net.Http.SocketsHttpHandler.Http2UnencryptedSupport", false);
AppContext.SetSwitch("System.Net.Http.SocketsHttpHandler.Http2Support", false);
}
}
public static async Task CallService(string urlGrpc, Func<GrpcChannel, Task> func)
{
AppContext.SetSwitch("System.Net.Http.SocketsHttpHandler.Http2UnencryptedSupport", true);
AppContext.SetSwitch("System.Net.Http.SocketsHttpHandler.Http2Support", true);
/*
using var httpClientHandler = new HttpClientHandler
{
ServerCertificateCustomValidationCallback = (message, cert, chain, errors) => { return true; }
};
*/
var channel = GrpcChannel.ForAddress(urlGrpc);
Log.Debug("Creating grpc client base address {@httpClient.BaseAddress} ", channel.Target);
try
{
await func(channel);
}
catch (RpcException e)
{
Log.Error("Error calling via grpc: {Status} - {Message}", e.Status, e.Message);
}
finally
{
AppContext.SetSwitch("System.Net.Http.SocketsHttpHandler.Http2UnencryptedSupport", false);
AppContext.SetSwitch("System.Net.Http.SocketsHttpHandler.Http2Support", false);
}
}
}
}

Loading…
Cancel
Save