remove old grpc caller
This commit is contained in:
parent
6fc60480c1
commit
71eda6aeb9
@ -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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -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…
x
Reference in New Issue
Block a user