Skip to content

Commit

Permalink
Feat(deadline) replaced bean deadlineStubTransformer with deadlineGrp…
Browse files Browse the repository at this point in the history
…cChannelConfigurer
  • Loading branch information
Бацура Сергей Александрович authored and Бацура Сергей Александрович committed Sep 5, 2024
1 parent 809bc5b commit 66e240f
Showing 1 changed file with 9 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;

/**
Expand All @@ -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.
*
*
Expand All @@ -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));
}
};
}
Expand Down

0 comments on commit 66e240f

Please sign in to comment.