From 66e240f3e341273dc62cc11adfc12bd3135c9212 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=91=D0=B0=D1=86=D1=83=D1=80=D0=B0=20=D0=A1=D0=B5=D1=80?= =?UTF-8?q?=D0=B3=D0=B5=D0=B9=20=D0=90=D0=BB=D0=B5=D0=BA=D1=81=D0=B0=D0=BD?= =?UTF-8?q?=D0=B4=D1=80=D0=BE=D0=B2=D0=B8=D1=87?= Date: Thu, 5 Sep 2024 08:54:49 +0300 Subject: [PATCH] Feat(deadline) replaced bean deadlineStubTransformer with deadlineGrpcChannelConfigurer --- .../GrpcClientDeadlineAutoConfiguration.java | 20 +++++++++---------- 1 file changed, 9 insertions(+), 11 deletions(-) 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 8fdb9773e..8f6f0a4c6 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,6 +18,8 @@ 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; @@ -26,9 +28,8 @@ import io.grpc.Channel; import io.grpc.MethodDescriptor; import lombok.extern.slf4j.Slf4j; -import net.devh.boot.grpc.client.config.GrpcChannelProperties; +import net.devh.boot.grpc.client.channelfactory.GrpcChannelConfigurer; import net.devh.boot.grpc.client.config.GrpcChannelsProperties; -import net.devh.boot.grpc.client.inject.StubTransformer; import net.devh.boot.grpc.client.interceptor.DeadlineSetupClientInterceptor; /** @@ -50,7 +51,7 @@ public class GrpcClientDeadlineAutoConfiguration { /** - * Creates a {@link StubTransformer} bean with interceptor that will call withDeadlineAfter with deadline from + * Creates a {@link GrpcChannelConfigurer} bean with interceptor that will call withDeadlineAfter with deadline from * props. * * @@ -59,16 +60,13 @@ public class GrpcClientDeadlineAutoConfiguration { * @see DeadlineSetupClientInterceptor#interceptCall(MethodDescriptor, CallOptions, Channel) */ @Bean - StubTransformer deadlineStubTransformer(final GrpcChannelsProperties props) { + GrpcChannelConfigurer deadlineGrpcChannelConfigurer(final GrpcChannelsProperties props) { requireNonNull(props, "properties"); - return (name, stub) -> { - GrpcChannelProperties channelProps = props.getChannel(name); - if (channelProps != null && channelProps.getDeadline() != null - && channelProps.getDeadline().toMillis() > 0L) { - return stub.withInterceptors(new DeadlineSetupClientInterceptor(channelProps.getDeadline())); - } else { - return stub; + return (channel, name) -> { + Duration deadline = props.getChannel(name).getDeadline(); + if (deadline != null && deadline.toMillis() > 0L) { + channel.intercept(new DeadlineSetupClientInterceptor(deadline)); } }; }