@@ -128,13 +128,60 @@ public GrpcChannelConfigurer keepAliveClientConfigurer() {
128
128
129
129
### ClientInterceptor
130
130
131
+ ` ClientInterceptor ` s can be used for various tasks, including:
132
+
133
+ - Authentication/Authorization
134
+ - Request validation
135
+ - Response filtering
136
+ - Attaching additional context to the call (e.g. tracing ids)
137
+ - Exception to error ` Status ` response mapping
138
+ - Logging
139
+ - ...
140
+
131
141
There are three ways to add a ` ClientInterceptor ` to your channel.
132
142
133
143
- Define the ` ClientInterceptor ` as a global interceptor using either the ` @GrpcGlobalClientInterceptor ` annotation,
134
144
or a ` GlobalClientInterceptorConfigurer `
135
145
- Explicitly list them in the ` @GrpcClient#interceptors ` or ` @GrpcClient#interceptorNames ` field
136
146
- Use a ` StubTransformer ` and call ` stub.withInterceptors(ClientInterceptor... interceptors) `
137
147
148
+ The following examples demonstrate how to use annotations to create a global client interceptor:
149
+
150
+ ```` java
151
+ @Configuration
152
+ public class ThirdPartyInterceptorConfig {}
153
+
154
+ @GrpcGlobalServerInterceptor
155
+ ServerInterceptor logServerInterceptor() {
156
+ return new LogGrpcInterceptor ();
157
+ }
158
+
159
+ }
160
+ ````
161
+
162
+ This variant is very handy if you wish to add third-party interceptors to the global scope.
163
+
164
+ For your own interceptor implementations you can achieve the same result by adding the annotation to the class itself:
165
+
166
+ ```` java
167
+ @GrpcGlobalServerInterceptor
168
+ public class LogGrpcInterceptor implements ServerInterceptor {
169
+
170
+ private static final Logger log = LoggerFactory . getLogger(LogGrpcInterceptor . class);
171
+
172
+ @Override
173
+ public <ReqT , RespT > ServerCall .Listener<ReqT > interceptCall (
174
+ ServerCall<ReqT , RespT > serverCall ,
175
+ Metadata metadata ,
176
+ ServerCallHandler<ReqT , RespT > serverCallHandler ) {
177
+
178
+ log. info(serverCall. getMethodDescriptor(). getFullMethodName());
179
+ return serverCallHandler. startCall(serverCall, metadata);
180
+ }
181
+
182
+ }
183
+ ````
184
+
138
185
### StubFactory
139
186
140
187
A ` StubFactory ` is used to create a ` Stub ` of a specific type. The registered stub factories will be checked in order
0 commit comments