gRPC config - client interceptors (#24339)

Co-authored-by: Rick Anderson <3605364+Rick-Anderson@users.noreply.github.com>
pull/24342/head
James Newton-King 2021-12-17 11:37:21 +13:00 committed by GitHub
parent f0c0eb0b8e
commit 18f74267fd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 29 additions and 0 deletions

View File

@ -69,6 +69,10 @@ The following code:
[!code-csharp[](~/grpc/configuration/sample/Program.cs?name=snippet&highlight=3-8)]
Note that client interceptors aren't configured with `GrpcChannelOptions`. Instead, client interceptors are configured using the `Intercept` extension method with a channel. This extension method is in the `Grpc.Core.Interceptors` namespace.
[!code-csharp[](~/grpc/configuration/sample/Program2.cs?name=snippet&highlight=4)]
[!INCLUDE[](~/includes/gRPCazure.md)]
## Additional resources

View File

@ -0,0 +1,25 @@
using System;
using System.Threading.Tasks;
using Greet;
using Grpc.Core;
using Grpc.Core.Interceptors;
using Grpc.Net.Client;
namespace GrpcGreeterClient
{
class Program
{
#region snippet
static async Task Main(string[] args)
{
var channel = GrpcChannel.ForAddress("https://localhost:5001");
var callInvoker = channel.Intercept(new LoggingInterceptor());
var client = new Greeter.GreeterClient(callInvoker);
var reply = await client.SayHelloAsync(
new HelloRequest { Name = "GreeterClient" });
Console.WriteLine("Greeting: " + reply.Message);
}
#endregion
}
}