Skip to content

Commit 3dd7f2c

Browse files
authored
Merge pull request #579 from a-simeshin/fix-docs-client-interceptor-configuration-example
Fix in docs client configuration examples with server interceptors
2 parents 3e4deca + 91bff70 commit 3dd7f2c

File tree

1 file changed

+26
-12
lines changed

1 file changed

+26
-12
lines changed

docs/en/client/configuration.md

Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -158,34 +158,48 @@ The following examples demonstrate how to use annotations to create a global cli
158158

159159
````java
160160
@Configuration
161-
public class ThirdPartyInterceptorConfig {}
161+
public class GlobalInterceptorConfiguration {
162162

163-
@GrpcGlobalServerInterceptor
164-
LogGrpcInterceptor logServerInterceptor() {
163+
@GrpcGlobalClientInterceptor
164+
LogGrpcInterceptor logClientInterceptor() {
165165
return new LogGrpcInterceptor();
166166
}
167167

168168
}
169169
````
170170

171-
This variant is very handy if you wish to add third-party interceptors to the global scope.
171+
The following example demonstrates creation via `GlobalClientInterceptorConfigurer`
172+
173+
````java
174+
@Configuration
175+
public class GlobalInterceptorConfiguration {
176+
177+
@Bean
178+
GlobalClientInterceptorConfigurer globalClientInterceptorConfigurer() {
179+
interceptors -> interceptors.add(new LogGrpcInterceptor());
180+
}
181+
182+
}
183+
````
184+
185+
These variant are very handy if you wish to add third-party interceptors to the global scope.
172186

173187
For your own interceptor implementations you can achieve the same result by adding the annotation to the class itself:
174188

175189
````java
176-
@GrpcGlobalServerInterceptor
177-
public class LogGrpcInterceptor implements ServerInterceptor {
190+
@GrpcGlobalClientInterceptor
191+
public class LogGrpcInterceptor implements ClientInterceptor {
178192

179193
private static final Logger log = LoggerFactory.getLogger(LogGrpcInterceptor.class);
180194

181195
@Override
182-
public <ReqT, RespT> ServerCall.Listener<ReqT> interceptCall(
183-
ServerCall<ReqT, RespT> serverCall,
184-
Metadata metadata,
185-
ServerCallHandler<ReqT, RespT> serverCallHandler) {
196+
public <ReqT, RespT> ClientCall<ReqT, RespT> interceptCall(
197+
final MethodDescriptor<ReqT, RespT> method,
198+
final CallOptions callOptions,
199+
final Channel next) {
186200

187-
log.info(serverCall.getMethodDescriptor().getFullMethodName());
188-
return serverCallHandler.startCall(serverCall, metadata);
201+
log.info(method.getFullMethodName());
202+
return next.newCall(method, callOptions);
189203
}
190204

191205
}

0 commit comments

Comments
 (0)