From 91bff7009b493cee149dc75727b7fe4cc7550fb2 Mon Sep 17 00:00:00 2001 From: a-simeshin Date: Thu, 2 Sep 2021 19:30:14 +0300 Subject: [PATCH] Fix in docs client configuration examples with server interceptors. Add usage example for GlobalClientInterceptorConfigurer --- docs/en/client/configuration.md | 38 ++++++++++++++++++++++----------- 1 file changed, 26 insertions(+), 12 deletions(-) diff --git a/docs/en/client/configuration.md b/docs/en/client/configuration.md index 6c33be934..c025ea09a 100644 --- a/docs/en/client/configuration.md +++ b/docs/en/client/configuration.md @@ -158,34 +158,48 @@ The following examples demonstrate how to use annotations to create a global cli ````java @Configuration -public class ThirdPartyInterceptorConfig {} +public class GlobalInterceptorConfiguration { - @GrpcGlobalServerInterceptor - LogGrpcInterceptor logServerInterceptor() { + @GrpcGlobalClientInterceptor + LogGrpcInterceptor logClientInterceptor() { return new LogGrpcInterceptor(); } } ```` -This variant is very handy if you wish to add third-party interceptors to the global scope. +The following example demonstrates creation via `GlobalClientInterceptorConfigurer` + +````java +@Configuration +public class GlobalInterceptorConfiguration { + + @Bean + GlobalClientInterceptorConfigurer globalClientInterceptorConfigurer() { + interceptors -> interceptors.add(new LogGrpcInterceptor()); + } + +} +```` + +These variant are very handy if you wish to add third-party interceptors to the global scope. For your own interceptor implementations you can achieve the same result by adding the annotation to the class itself: ````java -@GrpcGlobalServerInterceptor -public class LogGrpcInterceptor implements ServerInterceptor { +@GrpcGlobalClientInterceptor +public class LogGrpcInterceptor implements ClientInterceptor { private static final Logger log = LoggerFactory.getLogger(LogGrpcInterceptor.class); @Override - public ServerCall.Listener interceptCall( - ServerCall serverCall, - Metadata metadata, - ServerCallHandler serverCallHandler) { + public ClientCall interceptCall( + final MethodDescriptor method, + final CallOptions callOptions, + final Channel next) { - log.info(serverCall.getMethodDescriptor().getFullMethodName()); - return serverCallHandler.startCall(serverCall, metadata); + log.info(method.getFullMethodName()); + return next.newCall(method, callOptions); } }