Skip to content

Commit 66e240f

Browse files
Бацура Сергей АлександровичБацура Сергей Александрович
Бацура Сергей Александрович
authored and
Бацура Сергей Александрович
committed
Feat(deadline) replaced bean deadlineStubTransformer with deadlineGrpcChannelConfigurer
1 parent 809bc5b commit 66e240f

File tree

1 file changed

+9
-11
lines changed

1 file changed

+9
-11
lines changed

grpc-client-spring-boot-starter/src/main/java/net/devh/boot/grpc/client/autoconfigure/GrpcClientDeadlineAutoConfiguration.java

+9-11
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818

1919
import static java.util.Objects.requireNonNull;
2020

21+
import java.time.Duration;
22+
2123
import org.springframework.boot.autoconfigure.AutoConfigureBefore;
2224
import org.springframework.context.annotation.Bean;
2325
import org.springframework.context.annotation.Configuration;
@@ -26,9 +28,8 @@
2628
import io.grpc.Channel;
2729
import io.grpc.MethodDescriptor;
2830
import lombok.extern.slf4j.Slf4j;
29-
import net.devh.boot.grpc.client.config.GrpcChannelProperties;
31+
import net.devh.boot.grpc.client.channelfactory.GrpcChannelConfigurer;
3032
import net.devh.boot.grpc.client.config.GrpcChannelsProperties;
31-
import net.devh.boot.grpc.client.inject.StubTransformer;
3233
import net.devh.boot.grpc.client.interceptor.DeadlineSetupClientInterceptor;
3334

3435
/**
@@ -50,7 +51,7 @@
5051
public class GrpcClientDeadlineAutoConfiguration {
5152

5253
/**
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
5455
* props.
5556
*
5657
*
@@ -59,16 +60,13 @@ public class GrpcClientDeadlineAutoConfiguration {
5960
* @see DeadlineSetupClientInterceptor#interceptCall(MethodDescriptor, CallOptions, Channel)
6061
*/
6162
@Bean
62-
StubTransformer deadlineStubTransformer(final GrpcChannelsProperties props) {
63+
GrpcChannelConfigurer deadlineGrpcChannelConfigurer(final GrpcChannelsProperties props) {
6364
requireNonNull(props, "properties");
6465

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));
7270
}
7371
};
7472
}

0 commit comments

Comments
 (0)