-
Notifications
You must be signed in to change notification settings - Fork 826
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feat(timeout) changed the name of timeout property to defaultRequestT…
…imeout
- Loading branch information
Бацура Сергей Александрович
authored and
Бацура Сергей Александрович
committed
Sep 6, 2024
1 parent
9db6998
commit 102d09e
Showing
7 changed files
with
39 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,42 +28,42 @@ | |
import lombok.extern.slf4j.Slf4j; | ||
import net.devh.boot.grpc.client.channelfactory.GrpcChannelConfigurer; | ||
import net.devh.boot.grpc.client.config.GrpcChannelsProperties; | ||
import net.devh.boot.grpc.client.interceptor.TimeoutSetupClientInterceptor; | ||
import net.devh.boot.grpc.client.interceptor.DefaultRequestTimeoutSetupClientInterceptor; | ||
|
||
/** | ||
* The request timeout autoconfiguration for the client. | ||
* The default request timeout autoconfiguration for the client. | ||
* | ||
* <p> | ||
* You can disable this config by using: | ||
* </p> | ||
* | ||
* <pre> | ||
* <code>@ImportAutoConfiguration(exclude = GrpcClientTimeoutAutoConfiguration.class)</code> | ||
* <code>@ImportAutoConfiguration(exclude = GrpcClientDefaultRequestTimeoutAutoConfiguration.class)</code> | ||
* </pre> | ||
* | ||
* @author Sergei Batsura ([email protected]) | ||
*/ | ||
@Slf4j | ||
@Configuration(proxyBeanMethods = false) | ||
@AutoConfigureBefore(GrpcClientAutoConfiguration.class) | ||
public class GrpcClientTimeoutAutoConfiguration { | ||
public class GrpcClientDefaultRequestTimeoutAutoConfiguration { | ||
|
||
/** | ||
* Creates a {@link GrpcChannelConfigurer} bean applying the default request timeout from config to each new call | ||
* using a {@link ClientInterceptor}. | ||
* | ||
* @param props The properties for timeout configuration. | ||
* @return The GrpcChannelConfigurer bean with interceptor if timeout is configured. | ||
* @see TimeoutSetupClientInterceptor | ||
* @see DefaultRequestTimeoutSetupClientInterceptor | ||
*/ | ||
@Bean | ||
GrpcChannelConfigurer timeoutGrpcChannelConfigurer(final GrpcChannelsProperties props) { | ||
requireNonNull(props, "properties"); | ||
|
||
return (channel, name) -> { | ||
Duration timeout = props.getChannel(name).getTimeout(); | ||
Duration timeout = props.getChannel(name).getDefaultRequestTimeout(); | ||
if (timeout != null && timeout.toMillis() > 0L) { | ||
channel.intercept(new TimeoutSetupClientInterceptor(timeout)); | ||
channel.intercept(new DefaultRequestTimeoutSetupClientInterceptor(timeout)); | ||
} | ||
}; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -34,12 +34,12 @@ | |
* @author Sergei Batsura ([email protected]) | ||
*/ | ||
@Slf4j | ||
public class TimeoutSetupClientInterceptor implements ClientInterceptor { | ||
public class DefaultRequestTimeoutSetupClientInterceptor implements ClientInterceptor { | ||
|
||
private final Duration timeout; | ||
private final Duration defaultRequestTimeout; | ||
|
||
public TimeoutSetupClientInterceptor(Duration timeout) { | ||
this.timeout = requireNonNull(timeout, "timeout"); | ||
public DefaultRequestTimeoutSetupClientInterceptor(Duration defaultRequestTimeout) { | ||
this.defaultRequestTimeout = requireNonNull(defaultRequestTimeout, "defaultRequestTimeout"); | ||
} | ||
|
||
@Override | ||
|
@@ -50,7 +50,7 @@ public <ReqT, RespT> ClientCall<ReqT, RespT> interceptCall( | |
|
||
if (callOptions.getDeadline() == null) { | ||
return next.newCall(method, | ||
callOptions.withDeadlineAfter(timeout.toMillis(), TimeUnit.MILLISECONDS)); | ||
callOptions.withDeadlineAfter(defaultRequestTimeout.toMillis(), TimeUnit.MILLISECONDS)); | ||
} else { | ||
return next.newCall(method, callOptions); | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters