18
18
19
19
import static java .util .Objects .requireNonNull ;
20
20
21
+ import java .time .Duration ;
22
+
21
23
import org .springframework .boot .autoconfigure .AutoConfigureBefore ;
22
24
import org .springframework .context .annotation .Bean ;
23
25
import org .springframework .context .annotation .Configuration ;
26
28
import io .grpc .Channel ;
27
29
import io .grpc .MethodDescriptor ;
28
30
import lombok .extern .slf4j .Slf4j ;
29
- import net .devh .boot .grpc .client .config . GrpcChannelProperties ;
31
+ import net .devh .boot .grpc .client .channelfactory . GrpcChannelConfigurer ;
30
32
import net .devh .boot .grpc .client .config .GrpcChannelsProperties ;
31
- import net .devh .boot .grpc .client .inject .StubTransformer ;
32
33
import net .devh .boot .grpc .client .interceptor .DeadlineSetupClientInterceptor ;
33
34
34
35
/**
50
51
public class GrpcClientDeadlineAutoConfiguration {
51
52
52
53
/**
53
- * Creates a {@link StubTransformer } bean with interceptor that will call withDeadlineAfter with deadline from
54
+ * Creates a {@link GrpcChannelConfigurer } bean with interceptor that will call withDeadlineAfter with deadline from
54
55
* props.
55
56
*
56
57
*
@@ -59,16 +60,13 @@ public class GrpcClientDeadlineAutoConfiguration {
59
60
* @see DeadlineSetupClientInterceptor#interceptCall(MethodDescriptor, CallOptions, Channel)
60
61
*/
61
62
@ Bean
62
- StubTransformer deadlineStubTransformer (final GrpcChannelsProperties props ) {
63
+ GrpcChannelConfigurer deadlineGrpcChannelConfigurer (final GrpcChannelsProperties props ) {
63
64
requireNonNull (props , "properties" );
64
65
65
- return (name , stub ) -> {
66
- GrpcChannelProperties channelProps = props .getChannel (name );
67
- if (channelProps != null && channelProps .getDeadline () != null
68
- && channelProps .getDeadline ().toMillis () > 0L ) {
69
- return stub .withInterceptors (new DeadlineSetupClientInterceptor (channelProps .getDeadline ()));
70
- } else {
71
- return stub ;
66
+ return (channel , name ) -> {
67
+ Duration deadline = props .getChannel (name ).getDeadline ();
68
+ if (deadline != null && deadline .toMillis () > 0L ) {
69
+ channel .intercept (new DeadlineSetupClientInterceptor (deadline ));
72
70
}
73
71
};
74
72
}
0 commit comments