diff --git a/grpc-client-spring-boot-starter/src/main/java/net/devh/boot/grpc/client/autoconfigure/GrpcClientDeadlineAutoConfiguration.java b/grpc-client-spring-boot-starter/src/main/java/net/devh/boot/grpc/client/autoconfigure/GrpcClientDeadlineAutoConfiguration.java index 9782cc404..8fdb9773e 100644 --- a/grpc-client-spring-boot-starter/src/main/java/net/devh/boot/grpc/client/autoconfigure/GrpcClientDeadlineAutoConfiguration.java +++ b/grpc-client-spring-boot-starter/src/main/java/net/devh/boot/grpc/client/autoconfigure/GrpcClientDeadlineAutoConfiguration.java @@ -18,8 +18,6 @@ import static java.util.Objects.requireNonNull; -import java.time.Duration; - import org.springframework.boot.autoconfigure.AutoConfigureBefore; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; @@ -32,7 +30,6 @@ import net.devh.boot.grpc.client.config.GrpcChannelsProperties; import net.devh.boot.grpc.client.inject.StubTransformer; import net.devh.boot.grpc.client.interceptor.DeadlineSetupClientInterceptor; -import net.devh.boot.grpc.client.interceptor.GrpcGlobalClientInterceptor; /** * The deadline autoconfiguration for the client. @@ -52,15 +49,13 @@ @AutoConfigureBefore(GrpcClientAutoConfiguration.class) public class GrpcClientDeadlineAutoConfiguration { - private final CallOptions.Key deadlineDuration = - CallOptions.Key.createWithDefault("deadlineDuration", null); - /** - * Creates a {@link StubTransformer} bean that will add the deadlineDuration to the callOptions for using in - * DeadlineSetupClientInterceptor. + * Creates a {@link StubTransformer} bean with interceptor that will call withDeadlineAfter with deadline from + * props. + * * * @param props The properties for deadline configuration. - * @return The StubTransformer bean that will add the deadlineDuration from properties to the callOptions. + * @return The StubTransformer bean with interceptor if deadline is configured. * @see DeadlineSetupClientInterceptor#interceptCall(MethodDescriptor, CallOptions, Channel) */ @Bean @@ -71,16 +66,11 @@ StubTransformer deadlineStubTransformer(final GrpcChannelsProperties props) { GrpcChannelProperties channelProps = props.getChannel(name); if (channelProps != null && channelProps.getDeadline() != null && channelProps.getDeadline().toMillis() > 0L) { - return stub.withOption(deadlineDuration, channelProps.getDeadline()); + return stub.withInterceptors(new DeadlineSetupClientInterceptor(channelProps.getDeadline())); } else { return stub; } }; } - @GrpcGlobalClientInterceptor - DeadlineSetupClientInterceptor deadlineClientInterceptor() { - return new DeadlineSetupClientInterceptor(deadlineDuration); - } - } diff --git a/grpc-client-spring-boot-starter/src/main/java/net/devh/boot/grpc/client/interceptor/DeadlineSetupClientInterceptor.java b/grpc-client-spring-boot-starter/src/main/java/net/devh/boot/grpc/client/interceptor/DeadlineSetupClientInterceptor.java index 4ff2329c5..60b1a6081 100644 --- a/grpc-client-spring-boot-starter/src/main/java/net/devh/boot/grpc/client/interceptor/DeadlineSetupClientInterceptor.java +++ b/grpc-client-spring-boot-starter/src/main/java/net/devh/boot/grpc/client/interceptor/DeadlineSetupClientInterceptor.java @@ -28,7 +28,7 @@ import lombok.extern.slf4j.Slf4j; /** - * Deadline setup client interceptor that create new deadline instance from deadlineDuration. + * Deadline setup client interceptor that create new deadline instance from defaultDeadline. * * @author Sergei Batsura (batsura.sa@gmail.com) */ @@ -37,7 +37,7 @@ @RequiredArgsConstructor public class DeadlineSetupClientInterceptor implements ClientInterceptor { - private final CallOptions.Key deadlineDuration; + private final Duration defaultDeadline; @Override public ClientCall interceptCall( @@ -45,9 +45,9 @@ public ClientCall interceptCall( final CallOptions callOptions, final Channel next) { - Duration duration = callOptions.getOption(deadlineDuration); - if (duration != null) { - return next.newCall(method, callOptions.withDeadlineAfter(duration.toMillis(), TimeUnit.MILLISECONDS)); + if (defaultDeadline != null) { + return next.newCall(method, + callOptions.withDeadlineAfter(defaultDeadline.toMillis(), TimeUnit.MILLISECONDS)); } else { return next.newCall(method, callOptions); } diff --git a/tests/src/test/java/net/devh/boot/grpc/test/interceptor/DefaultClientInterceptorTest.java b/tests/src/test/java/net/devh/boot/grpc/test/interceptor/DefaultClientInterceptorTest.java index 2db639b4c..17a51b931 100644 --- a/tests/src/test/java/net/devh/boot/grpc/test/interceptor/DefaultClientInterceptorTest.java +++ b/tests/src/test/java/net/devh/boot/grpc/test/interceptor/DefaultClientInterceptorTest.java @@ -33,7 +33,6 @@ import io.micrometer.core.instrument.binder.grpc.MetricCollectingClientInterceptor; import io.micrometer.core.instrument.binder.grpc.ObservationGrpcClientInterceptor; import net.devh.boot.grpc.client.autoconfigure.GrpcClientAutoConfiguration; -import net.devh.boot.grpc.client.interceptor.DeadlineSetupClientInterceptor; import net.devh.boot.grpc.client.interceptor.GlobalClientInterceptorRegistry; import net.devh.boot.grpc.client.metrics.MetricsClientInterceptor; @@ -55,7 +54,6 @@ void testDefaultInterceptors() { expected.add(this.applicationContext.getBean(MetricCollectingClientInterceptor.class)); expected.add(this.applicationContext.getBean(MetricsClientInterceptor.class)); expected.add(this.applicationContext.getBean(ObservationGrpcClientInterceptor.class)); - expected.add(this.applicationContext.getBean(DeadlineSetupClientInterceptor.class)); final List actual = new ArrayList<>(this.registry.getClientInterceptors()); assertThat(actual).containsExactlyInAnyOrderElementsOf(expected);