Fix config props defaults and descriptions
This commit simplifies the client properties by setting the default values directly on the properties and removes markdown from the property javadocs. This improves end user experience by adding default values and descriptions to the generated config props docs. Signed-off-by: Chris Bono <chris.bono@gmail.com>
This commit is contained in:
@@ -2,14 +2,47 @@
|
||||
|Name | Default | Description
|
||||
|
||||
|spring.grpc.client.channels | |
|
||||
|spring.grpc.client.default-channel.address | `+++static://localhost:9090+++` | The target address uri to connect to.
|
||||
|spring.grpc.client.default-channel.default-load-balancing-policy | `+++round_robin+++` | The default load balancing policy the channel should use.
|
||||
|spring.grpc.client.default-channel.enable-keep-alive | `+++false+++` | Whether keep alive is enabled on the channel.
|
||||
|spring.grpc.client.default-channel.health.enabled | `+++false+++` | Whether to enable client-side health check for the channel.
|
||||
|spring.grpc.client.default-channel.health.service-name | | Name of the service to check health on.
|
||||
|spring.grpc.client.default-channel.idle-timeout | `+++20s+++` | The duration without ongoing RPCs before going to idle mode.
|
||||
|spring.grpc.client.default-channel.keep-alive-time | `+++5m+++` | The delay before sending a keepAlive. Note that shorter intervals increase the network burden for the server and this value can not be lower than 'permitKeepAliveTime' on the server.
|
||||
|spring.grpc.client.default-channel.keep-alive-timeout | `+++20s+++` | The default timeout for a keepAlives ping request.
|
||||
|spring.grpc.client.default-channel.keep-alive-without-calls | `+++false+++` | Whether a keepAlive will be performed when there are no outstanding RPC on a connection.
|
||||
|spring.grpc.client.default-channel.max-inbound-message-size | `+++4194304B+++` | Maximum message size allowed to be received by the channel (default 4MiB). Set to '-1' to use the highest possible limit (not recommended).
|
||||
|spring.grpc.client.default-channel.max-inbound-metadata-size | `+++8192B+++` | Maximum metadata size allowed to be received by the channel (default 8KiB). Set to '-1' to use the highest possible limit (not recommended).
|
||||
|spring.grpc.client.default-channel.negotiation-type | | The negotiation type for the channel.
|
||||
|spring.grpc.client.default-channel.secure | `+++true+++` | Flag to say that strict SSL checks are not enabled (so the remote certificate could be anonymous).
|
||||
|spring.grpc.client.default-channel.ssl.bundle | | SSL bundle name.
|
||||
|spring.grpc.client.default-channel.ssl.enabled | | Whether to enable SSL support. Enabled automatically if "bundle" is provided unless specified otherwise.
|
||||
|spring.grpc.client.default-channel.user-agent | | The custom User-Agent for the channel.
|
||||
|spring.grpc.server.address | | The address to bind to. could be a host:port combination or a pseudo URL like static://host:port. Can not be set if host or port are set independently.
|
||||
|spring.grpc.server.exception-handling.enabled | `+++true+++` | Whether to enable user-defined global exception handling on the gRPC server.
|
||||
|spring.grpc.server.host | | Server address to bind to. The default is any IP address ('*').
|
||||
|spring.grpc.server.max-inbound-message-size | | Maximum message size allowed to be received by the server (default 4MiB).
|
||||
|spring.grpc.server.max-inbound-metadata-size | | Maximum metadata size allowed to be received by the server (default 8KiB).
|
||||
|spring.grpc.server.health.actuator.enabled | `+++true+++` | Whether to adapt Actuator health indicators into gRPC health checks.
|
||||
|spring.grpc.server.health.actuator.health-indicator-paths | | List of Actuator health indicator paths to adapt into gRPC health checks.
|
||||
|spring.grpc.server.health.actuator.update-initial-delay | `+++5s+++` | The initial delay before updating the health status the very first time.
|
||||
|spring.grpc.server.health.actuator.update-overall-health | `+++true+++` | Whether to update the overall gRPC server health (the '' service) with the aggregate status of the configured health indicators.
|
||||
|spring.grpc.server.health.actuator.update-rate | `+++5s+++` | How often to update the health status.
|
||||
|spring.grpc.server.health.enabled | `+++true+++` | Whether to auto-configure Health feature on the gRPC server.
|
||||
|spring.grpc.server.host | `+++*+++` | Server address to bind to. The default is any IP address ('*').
|
||||
|spring.grpc.server.keep-alive.max-age | | Maximum time a connection may exist before being gracefully terminated (default infinite).
|
||||
|spring.grpc.server.keep-alive.max-age-grace | | Maximum time for graceful connection termination (default infinite).
|
||||
|spring.grpc.server.keep-alive.max-idle | | Maximum time a connection can remain idle before being gracefully terminated (default infinite).
|
||||
|spring.grpc.server.keep-alive.permit-time | `+++5m+++` | Maximum keep-alive time clients are permitted to configure (default 5m).
|
||||
|spring.grpc.server.keep-alive.permit-without-calls | `+++false+++` | Whether clients are permitted to send keep alive pings when there are no outstanding RPCs on the connection (default false).
|
||||
|spring.grpc.server.keep-alive.time | `+++2h+++` | Duration without read activity before sending a keep alive ping (default 2h).
|
||||
|spring.grpc.server.keep-alive.timeout | `+++20s+++` | Maximum time to wait for read activity after sending a keep alive ping. If sender does not receive an acknowledgment within this time, it will close the connection (default 20s).
|
||||
|spring.grpc.server.max-inbound-message-size | `+++4194304B+++` | Maximum message size allowed to be received by the server (default 4MiB).
|
||||
|spring.grpc.server.max-inbound-metadata-size | `+++8192B+++` | Maximum metadata size allowed to be received by the server (default 8KiB).
|
||||
|spring.grpc.server.observations.enabled | `+++true+++` | Whether to enable Observations on the server.
|
||||
|spring.grpc.server.port | `+++9090+++` | Server port to listen on. When the value is 0, a random available port is selected. The default is 9090.
|
||||
|spring.grpc.server.reflection.enabled | `+++true+++` | Whether to enable Reflection on the gRPC server.
|
||||
|spring.grpc.server.shutdown-grace-period | | Maximum time to wait for the server to gracefully shutdown. When the value is negative, the server waits forever. When the value is 0, the server will force shutdown immediately. The default is 30 seconds.
|
||||
|spring.grpc.server.shutdown-grace-period | `+++30s+++` | Maximum time to wait for the server to gracefully shutdown. When the value is negative, the server waits forever. When the value is 0, the server will force shutdown immediately. The default is 30 seconds.
|
||||
|spring.grpc.server.ssl.bundle | | SSL bundle name.
|
||||
|spring.grpc.server.ssl.client-auth | | Client authentication mode.
|
||||
|spring.grpc.server.ssl.enabled | | Whether to enable SSL support. Enabled automatically if "bundle" is provided unless specified otherwise.
|
||||
|spring.grpc.server.ssl.secure | `+++true+++` | Flag to indicate that client authentication is secure (i.e. certificates are checked). Do not set this to false in production.
|
||||
|
||||
|===
|
||||
@@ -19,7 +19,7 @@ import java.time.Duration;
|
||||
import java.time.temporal.ChronoUnit;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
import org.springframework.boot.convert.DataSizeUnit;
|
||||
@@ -33,31 +33,22 @@ import org.springframework.grpc.client.NegotiationType;
|
||||
import org.springframework.util.unit.DataSize;
|
||||
import org.springframework.util.unit.DataUnit;
|
||||
|
||||
import io.grpc.LoadBalancerRegistry;
|
||||
import io.grpc.ManagedChannelBuilder;
|
||||
import io.grpc.internal.GrpcUtil;
|
||||
import io.grpc.netty.NettyChannelBuilder;
|
||||
|
||||
@ConfigurationProperties(prefix = "spring.grpc.client")
|
||||
public class GrpcClientProperties implements EnvironmentAware {
|
||||
|
||||
private NamedChannel defaultChannel = new NamedChannel();
|
||||
private final NamedChannel defaultChannel = new NamedChannel();
|
||||
|
||||
private Map<String, NamedChannel> channels = new HashMap<>();
|
||||
private final Map<String, NamedChannel> channels = new HashMap<>();
|
||||
|
||||
private Environment environment = new StandardEnvironment();
|
||||
|
||||
GrpcClientProperties() {
|
||||
this.defaultChannel.setAddress("static://localhost:9090");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setEnvironment(Environment environment) {
|
||||
this.environment = environment;
|
||||
}
|
||||
|
||||
public Map<String, NamedChannel> getChannels() {
|
||||
return channels;
|
||||
return this.channels;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -65,16 +56,15 @@ public class GrpcClientProperties implements EnvironmentAware {
|
||||
* @return the default {@link NamedChannel}
|
||||
*/
|
||||
public NamedChannel getDefaultChannel() {
|
||||
return defaultChannel;
|
||||
return this.defaultChannel;
|
||||
}
|
||||
|
||||
public NamedChannel getChannel(String name) {
|
||||
if ("default".equals(name)) {
|
||||
return defaultChannel;
|
||||
return this.defaultChannel;
|
||||
}
|
||||
return channels.computeIfAbsent(name, authority -> {
|
||||
NamedChannel channel = new NamedChannel();
|
||||
channel.copyDefaultsFrom(defaultChannel);
|
||||
return this.channels.computeIfAbsent(name, authority -> {
|
||||
NamedChannel channel = this.defaultChannel.copy();
|
||||
if (!authority.contains(":/") && !authority.startsWith("unix:")) {
|
||||
authority = "static://" + authority;
|
||||
}
|
||||
@@ -89,32 +79,21 @@ public class GrpcClientProperties implements EnvironmentAware {
|
||||
if (address.startsWith("static:") || address.startsWith("tcp:")) {
|
||||
address = address.substring(address.indexOf(":") + 1).replaceFirst("/*", "");
|
||||
}
|
||||
address = environment.resolvePlaceholders(address);
|
||||
return address.toString();
|
||||
address = this.environment.resolvePlaceholders(address);
|
||||
return address;
|
||||
}
|
||||
|
||||
public static class NamedChannel {
|
||||
|
||||
private String address = null;
|
||||
|
||||
/**
|
||||
* Gets the target address uri.
|
||||
* @return The address to connect to or null
|
||||
* @see #setAddress(String)
|
||||
* The target address uri to connect to.
|
||||
*/
|
||||
private String address = "static://localhost:9090";
|
||||
|
||||
public String getAddress() {
|
||||
return this.address;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the address uri for the channel. If nothing is configured then the name of
|
||||
* the client will be used along with the default scheme. We recommend explicitly
|
||||
* configuring the scheme used for the address resolutions such as {@code dns:/}.
|
||||
* @param address The address to use for the channel or null to default to the
|
||||
* fallback.
|
||||
*
|
||||
* @see #setAddress(String)
|
||||
*/
|
||||
public void setAddress(final String address) {
|
||||
this.address = address;
|
||||
}
|
||||
@@ -123,29 +102,15 @@ public class GrpcClientProperties implements EnvironmentAware {
|
||||
// defaultLoadBalancingPolicy
|
||||
// --------------------------------------------------
|
||||
|
||||
private String defaultLoadBalancingPolicy;
|
||||
|
||||
private static final String DEFAULT_DEFAULT_LOAD_BALANCING_POLICY = "round_robin";
|
||||
|
||||
/**
|
||||
* Gets the default load balancing policy this channel should use.
|
||||
* @return The default load balancing policy.
|
||||
* @see ManagedChannelBuilder#defaultLoadBalancingPolicy(String)
|
||||
* The default load balancing policy the channel should use.
|
||||
*/
|
||||
private String defaultLoadBalancingPolicy = "round_robin";
|
||||
|
||||
public String getDefaultLoadBalancingPolicy() {
|
||||
return this.defaultLoadBalancingPolicy == null ? DEFAULT_DEFAULT_LOAD_BALANCING_POLICY
|
||||
: this.defaultLoadBalancingPolicy;
|
||||
return this.defaultLoadBalancingPolicy;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the default load balancing policy for this channel. This config might be
|
||||
* overwritten by the service config received from the target address. The names
|
||||
* have to be resolvable from the {@link LoadBalancerRegistry}. By default this
|
||||
* the {@code round_robin} policy. Please note that this policy is different from
|
||||
* the normal grpc-java default policy {@code pick_first}.
|
||||
* @param defaultLoadBalancingPolicy The default load balancing policy to use or
|
||||
* null to use the fallback.
|
||||
*/
|
||||
public void setDefaultLoadBalancingPolicy(final String defaultLoadBalancingPolicy) {
|
||||
this.defaultLoadBalancingPolicy = defaultLoadBalancingPolicy;
|
||||
}
|
||||
@@ -159,13 +124,12 @@ public class GrpcClientProperties implements EnvironmentAware {
|
||||
}
|
||||
|
||||
/**
|
||||
* The negotiation type for the channel. Default is
|
||||
* {@link NegotiationType#PLAINTEXT}.
|
||||
* The negotiation type for the channel.
|
||||
*/
|
||||
private NegotiationType negotiationType = NegotiationType.PLAINTEXT;
|
||||
|
||||
public NegotiationType getNegotiationType() {
|
||||
return negotiationType;
|
||||
return this.negotiationType;
|
||||
}
|
||||
|
||||
public void setNegotiationType(NegotiationType negotiationType) {
|
||||
@@ -176,144 +140,82 @@ public class GrpcClientProperties implements EnvironmentAware {
|
||||
// KeepAlive
|
||||
// --------------------------------------------------
|
||||
|
||||
private Boolean enableKeepAlive;
|
||||
|
||||
private static final boolean DEFAULT_ENABLE_KEEP_ALIVE = false;
|
||||
|
||||
/**
|
||||
* Gets whether keepAlive is enabled.
|
||||
* @return True, if keep alive should be enabled. False otherwise.
|
||||
*
|
||||
* @see #setEnableKeepAlive(Boolean)
|
||||
* Whether keep alive is enabled on the channel.
|
||||
*/
|
||||
private boolean enableKeepAlive = false;
|
||||
|
||||
public boolean isEnableKeepAlive() {
|
||||
return this.enableKeepAlive == null ? DEFAULT_ENABLE_KEEP_ALIVE : this.enableKeepAlive;
|
||||
return this.enableKeepAlive;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets whether keepAlive should be enabled. Defaults to false.
|
||||
* @param enableKeepAlive True, to enable. False, to disable. Null, to use the
|
||||
* fallback.
|
||||
*/
|
||||
public void setEnableKeepAlive(final Boolean enableKeepAlive) {
|
||||
public void setEnableKeepAlive(boolean enableKeepAlive) {
|
||||
this.enableKeepAlive = enableKeepAlive;
|
||||
}
|
||||
|
||||
// --------------------------------------------------
|
||||
|
||||
@DurationUnit(ChronoUnit.SECONDS)
|
||||
private Duration idleTimeout;
|
||||
|
||||
private static final Duration DEFAULT_IDLE_TIMEOUT = Duration.of(20, ChronoUnit.SECONDS);
|
||||
|
||||
/**
|
||||
* Gets the idle timeout.
|
||||
* @return The idle tomeout.
|
||||
*
|
||||
* @see #setIdleTimeout(Duration)
|
||||
* The duration without ongoing RPCs before going to idle mode.
|
||||
*/
|
||||
@DurationUnit(ChronoUnit.SECONDS)
|
||||
private Duration idleTimeout = Duration.ofSeconds(20);
|
||||
|
||||
public Duration getIdleTimeout() {
|
||||
return this.idleTimeout == null ? DEFAULT_IDLE_TIMEOUT : this.idleTimeout;
|
||||
return this.idleTimeout;
|
||||
}
|
||||
|
||||
/**
|
||||
* The idle timeout.
|
||||
* @param idleTimeout The new idle timeout, or null to use the fallback.
|
||||
*
|
||||
*/
|
||||
public void setIdleTimeout(final Duration idleTimeout) {
|
||||
public void setIdleTimeout(Duration idleTimeout) {
|
||||
this.idleTimeout = idleTimeout;
|
||||
}
|
||||
|
||||
// --------------------------------------------------
|
||||
|
||||
@DurationUnit(ChronoUnit.SECONDS)
|
||||
private Duration keepAliveTime;
|
||||
|
||||
private static final Duration DEFAULT_KEEP_ALIVE_TIME = Duration.of(5, ChronoUnit.MINUTES);
|
||||
|
||||
/**
|
||||
* Gets the default delay before we send a keepAlive.
|
||||
* @return The default delay before sending keepAlives.
|
||||
*
|
||||
* @see #setKeepAliveTime(Duration)
|
||||
* The delay before sending a keepAlive. Note that shorter intervals increase the
|
||||
* network burden for the server and this value can not be lower than
|
||||
* 'permitKeepAliveTime' on the server.
|
||||
*/
|
||||
@DurationUnit(ChronoUnit.SECONDS)
|
||||
private Duration keepAliveTime = Duration.ofMinutes(5);
|
||||
|
||||
public Duration getKeepAliveTime() {
|
||||
return this.keepAliveTime == null ? DEFAULT_KEEP_ALIVE_TIME : this.keepAliveTime;
|
||||
return this.keepAliveTime;
|
||||
}
|
||||
|
||||
/**
|
||||
* The default delay before we send a keepAlives. Defaults to {@code 5min}.
|
||||
* Default unit {@link ChronoUnit#SECONDS SECONDS}. Please note that shorter
|
||||
* intervals increase the network burden for the server. Cannot be lower than
|
||||
* permitKeepAliveTime on server (default 5min).
|
||||
* @param keepAliveTime The new default delay before sending keepAlives, or null
|
||||
* to use the fallback.
|
||||
*
|
||||
* @see #setEnableKeepAlive(Boolean)
|
||||
* @see NettyChannelBuilder#keepAliveTime(long, TimeUnit)
|
||||
*/
|
||||
public void setKeepAliveTime(final Duration keepAliveTime) {
|
||||
public void setKeepAliveTime(Duration keepAliveTime) {
|
||||
this.keepAliveTime = keepAliveTime;
|
||||
}
|
||||
|
||||
// --------------------------------------------------
|
||||
|
||||
@DurationUnit(ChronoUnit.SECONDS)
|
||||
private Duration keepAliveTimeout;
|
||||
|
||||
private static final Duration DEFAULT_KEEP_ALIVE_TIMEOUT = Duration.of(20, ChronoUnit.SECONDS);
|
||||
|
||||
/**
|
||||
* The default timeout for a keepAlives ping request.
|
||||
* @return The default timeout for a keepAlives ping request.
|
||||
*
|
||||
* @see #setKeepAliveTimeout(Duration)
|
||||
*/
|
||||
@DurationUnit(ChronoUnit.SECONDS)
|
||||
private Duration keepAliveTimeout = Duration.ofSeconds(20);
|
||||
|
||||
public Duration getKeepAliveTimeout() {
|
||||
return this.keepAliveTimeout == null ? DEFAULT_KEEP_ALIVE_TIMEOUT : this.keepAliveTimeout;
|
||||
return this.keepAliveTimeout;
|
||||
}
|
||||
|
||||
/**
|
||||
* The default timeout for a keepAlives ping request. Defaults to {@code 20s}.
|
||||
* Default unit {@link ChronoUnit#SECONDS SECONDS}.
|
||||
* @param keepAliveTimeout The default timeout for a keepAlives ping request.
|
||||
*
|
||||
* @see #setEnableKeepAlive(Boolean)
|
||||
* @see NettyChannelBuilder#keepAliveTimeout(long, TimeUnit)
|
||||
*/
|
||||
public void setKeepAliveTimeout(final Duration keepAliveTimeout) {
|
||||
public void setKeepAliveTimeout(Duration keepAliveTimeout) {
|
||||
this.keepAliveTimeout = keepAliveTimeout;
|
||||
}
|
||||
|
||||
// --------------------------------------------------
|
||||
|
||||
private Boolean keepAliveWithoutCalls;
|
||||
|
||||
private static final boolean DEFAULT_KEEP_ALIVE_WITHOUT_CALLS = false;
|
||||
|
||||
/**
|
||||
* Gets whether keepAlive will be performed when there are no outstanding RPC on a
|
||||
* Whether a keepAlive will be performed when there are no outstanding RPC on a
|
||||
* connection.
|
||||
* @return True, if keepAlives should be performed even when there are no RPCs.
|
||||
* False otherwise.
|
||||
*
|
||||
* @see #setKeepAliveWithoutCalls(Boolean)
|
||||
*/
|
||||
private boolean keepAliveWithoutCalls = false;
|
||||
|
||||
public boolean isKeepAliveWithoutCalls() {
|
||||
return this.keepAliveWithoutCalls == null ? DEFAULT_KEEP_ALIVE_WITHOUT_CALLS : this.keepAliveWithoutCalls;
|
||||
return this.keepAliveWithoutCalls;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets whether keepAlive will be performed when there are no outstanding RPC on a
|
||||
* connection. Defaults to {@code false}.
|
||||
* @param keepAliveWithoutCalls whether keepAlive will be performed when there are
|
||||
* no outstanding RPC on a connection.
|
||||
*
|
||||
* @see #setEnableKeepAlive(Boolean)
|
||||
* @see NettyChannelBuilder#keepAliveWithoutCalls(boolean)
|
||||
*/
|
||||
public void setKeepAliveWithoutCalls(final Boolean keepAliveWithoutCalls) {
|
||||
public void setKeepAliveWithoutCalls(boolean keepAliveWithoutCalls) {
|
||||
this.keepAliveWithoutCalls = keepAliveWithoutCalls;
|
||||
}
|
||||
|
||||
@@ -321,151 +223,85 @@ public class GrpcClientProperties implements EnvironmentAware {
|
||||
// Message Transfer
|
||||
// --------------------------------------------------
|
||||
|
||||
/**
|
||||
* Maximum message size allowed to be received by the channel (default 4MiB). Set
|
||||
* to '-1' to use the highest possible limit (not recommended).
|
||||
*/
|
||||
@DataSizeUnit(DataUnit.BYTES)
|
||||
private DataSize maxInboundMessageSize = null;
|
||||
private DataSize maxInboundMessageSize = DataSize.ofBytes(4194304);
|
||||
|
||||
/**
|
||||
* Gets the maximum message size allowed to be received by the channel. If not set
|
||||
* ({@code null}) then {@link GrpcUtil#DEFAULT_MAX_MESSAGE_SIZE gRPC's default}
|
||||
* should be used. If set to {@code -1} then it will use the highest possible
|
||||
* limit (not recommended).
|
||||
* @return The maximum message size allowed or null if the default should be used.
|
||||
*
|
||||
* @see #setMaxInboundMessageSize(DataSize)
|
||||
* Maximum metadata size allowed to be received by the channel (default 8KiB). Set
|
||||
* to '-1' to use the highest possible limit (not recommended).
|
||||
*/
|
||||
@DataSizeUnit(DataUnit.BYTES)
|
||||
private DataSize maxInboundMetadataSize = DataSize.ofBytes(8192);
|
||||
|
||||
public DataSize getMaxInboundMessageSize() {
|
||||
return this.maxInboundMessageSize;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the maximum message size in bytes allowed to be received by the channel.
|
||||
* If not set ({@code null}) then it will default to
|
||||
* {@link GrpcUtil#DEFAULT_MAX_MESSAGE_SIZE gRPC's default}. If set to {@code -1}
|
||||
* then it will use the highest possible limit (not recommended).
|
||||
* @param maxInboundMessageSize The new maximum size in bytes allowed for incoming
|
||||
* messages. {@code -1} for max possible. Null to use the gRPC's default.
|
||||
*
|
||||
* @see ManagedChannelBuilder#maxInboundMessageSize(int)
|
||||
*/
|
||||
public void setMaxInboundMessageSize(final DataSize maxInboundMessageSize) {
|
||||
if (maxInboundMessageSize == null || maxInboundMessageSize.toBytes() >= 0) {
|
||||
this.maxInboundMessageSize = maxInboundMessageSize;
|
||||
}
|
||||
else if (maxInboundMessageSize.toBytes() == -1) {
|
||||
this.maxInboundMessageSize = DataSize.ofBytes(Integer.MAX_VALUE);
|
||||
}
|
||||
else {
|
||||
throw new IllegalArgumentException("Unsupported maxInboundMessageSize: " + maxInboundMessageSize);
|
||||
}
|
||||
this.setMaxInboundSize(maxInboundMessageSize, (s) -> this.maxInboundMessageSize = s,
|
||||
"maxInboundMesssageSize");
|
||||
}
|
||||
|
||||
@DataSizeUnit(DataUnit.BYTES)
|
||||
private DataSize maxInboundMetadataSize = null;
|
||||
|
||||
/**
|
||||
* Sets the maximum size of metadata in bytes allowed to be received. If not set
|
||||
* ({@code null}) then it will default to gRPC's default. The default is
|
||||
* implementation-dependent, but is not generally less than 8 KiB and may be
|
||||
* unlimited. If set to {@code -1} then it will use the highest possible limit
|
||||
* (not recommended). Integer.MAX_VALUE disables the enforcement.
|
||||
* @return The maximum size of metadata in bytes allowed to be received or null if
|
||||
* the default should be used.
|
||||
*
|
||||
* @see ManagedChannelBuilder#maxInboundMetadataSize(int) (int)
|
||||
*/
|
||||
public DataSize getMaxInboundMetadataSize() {
|
||||
return maxInboundMetadataSize;
|
||||
return this.maxInboundMetadataSize;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the maximum size of metadata in bytes allowed to be received. If not set
|
||||
* ({@code null}) then it will default.The default is implementation-dependent,
|
||||
* but is not generally less than 8 KiB and may be unlimited. If set to {@code -1}
|
||||
* then it will use the highest possible limit (not recommended).
|
||||
* Integer.MAX_VALUE disables the enforcement.
|
||||
* @param maxInboundMetadataSize The new maximum size of metadata in bytes allowed
|
||||
* to be received. {@code -1} for max possible. Null to use the gRPC's default.
|
||||
*
|
||||
* @see ManagedChannelBuilder#maxInboundMetadataSize(int) (int)
|
||||
*/
|
||||
public void setMaxInboundMetadataSize(DataSize maxInboundMetadataSize) {
|
||||
if (maxInboundMetadataSize == null || maxInboundMetadataSize.toBytes() >= 0) {
|
||||
this.maxInboundMetadataSize = maxInboundMetadataSize;
|
||||
this.setMaxInboundSize(maxInboundMetadataSize, (s) -> this.maxInboundMetadataSize = s,
|
||||
"maxInboundMetadataSize");
|
||||
}
|
||||
|
||||
private void setMaxInboundSize(DataSize maxSize, Consumer<DataSize> setter, String propertyName) {
|
||||
if (maxSize != null && maxSize.toBytes() >= 0) {
|
||||
setter.accept(maxSize);
|
||||
}
|
||||
else if (maxInboundMetadataSize.toBytes() == -1) {
|
||||
this.maxInboundMetadataSize = DataSize.ofBytes(Integer.MAX_VALUE);
|
||||
else if (maxSize != null && maxSize.toBytes() == -1) {
|
||||
setter.accept(DataSize.ofBytes(Integer.MAX_VALUE));
|
||||
}
|
||||
else {
|
||||
throw new IllegalArgumentException("Unsupported maxInboundMetadataSize: " + maxInboundMetadataSize);
|
||||
throw new IllegalArgumentException("Unsupported %s: %s".formatted(propertyName, maxSize));
|
||||
}
|
||||
}
|
||||
|
||||
// --------------------------------------------------
|
||||
|
||||
/**
|
||||
* The custom User-Agent for the channel.
|
||||
*/
|
||||
private String userAgent = null;
|
||||
|
||||
/**
|
||||
* Get custom User-Agent for the channel.
|
||||
* @return custom User-Agent for the channel.
|
||||
*
|
||||
* @see #setUserAgent(String)
|
||||
*/
|
||||
public String getUserAgent() {
|
||||
return this.userAgent;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets custom User-Agent HTTP header.
|
||||
* @param userAgent Custom User-Agent.
|
||||
*
|
||||
* @see ManagedChannelBuilder#userAgent(String)
|
||||
*/
|
||||
public void setUserAgent(final String userAgent) {
|
||||
this.userAgent = userAgent;
|
||||
}
|
||||
|
||||
/**
|
||||
* Copies the defaults from the given configuration. Values are considered
|
||||
* "default" if they are null. Please note that the getters might return fallback
|
||||
* values instead.
|
||||
* @param config The config to copy the defaults from.
|
||||
* Provide a copy of the channel instance.
|
||||
* @return a copy of the channel instance.
|
||||
*/
|
||||
public void copyDefaultsFrom(final NamedChannel config) {
|
||||
if (this == config) {
|
||||
return;
|
||||
}
|
||||
if (this.address == null) {
|
||||
this.address = config.address;
|
||||
}
|
||||
if (this.defaultLoadBalancingPolicy == null) {
|
||||
this.defaultLoadBalancingPolicy = config.defaultLoadBalancingPolicy;
|
||||
}
|
||||
if (this.enableKeepAlive == null) {
|
||||
this.enableKeepAlive = config.enableKeepAlive;
|
||||
}
|
||||
if (this.idleTimeout == null) {
|
||||
this.idleTimeout = config.idleTimeout;
|
||||
}
|
||||
if (this.keepAliveTime == null) {
|
||||
this.keepAliveTime = config.keepAliveTime;
|
||||
}
|
||||
if (this.keepAliveTimeout == null) {
|
||||
this.keepAliveTimeout = config.keepAliveTimeout;
|
||||
}
|
||||
if (this.keepAliveWithoutCalls == null) {
|
||||
this.keepAliveWithoutCalls = config.keepAliveWithoutCalls;
|
||||
}
|
||||
if (this.maxInboundMessageSize == null) {
|
||||
this.maxInboundMessageSize = config.maxInboundMessageSize;
|
||||
}
|
||||
if (this.maxInboundMetadataSize == null) {
|
||||
this.maxInboundMetadataSize = config.maxInboundMetadataSize;
|
||||
}
|
||||
if (this.userAgent == null) {
|
||||
this.userAgent = config.userAgent;
|
||||
}
|
||||
this.health.copyDefaultsFrom(config.health);
|
||||
this.ssl.copyDefaultsFrom(config.ssl);
|
||||
public NamedChannel copy() {
|
||||
NamedChannel copy = new NamedChannel();
|
||||
copy.address = this.address;
|
||||
copy.defaultLoadBalancingPolicy = this.defaultLoadBalancingPolicy;
|
||||
copy.negotiationType = this.negotiationType;
|
||||
copy.enableKeepAlive = this.enableKeepAlive;
|
||||
copy.idleTimeout = this.idleTimeout;
|
||||
copy.keepAliveTime = this.keepAliveTime;
|
||||
copy.keepAliveTimeout = this.keepAliveTimeout;
|
||||
copy.keepAliveWithoutCalls = this.keepAliveWithoutCalls;
|
||||
copy.maxInboundMessageSize = this.maxInboundMessageSize;
|
||||
copy.maxInboundMetadataSize = this.maxInboundMetadataSize;
|
||||
copy.userAgent = this.userAgent;
|
||||
copy.health.copyValuesFrom(this.getHealth());
|
||||
copy.ssl.copyValuesFrom(this.getSsl());
|
||||
return copy;
|
||||
}
|
||||
|
||||
// --------------------------------------------------
|
||||
@@ -509,16 +345,6 @@ public class GrpcClientProperties implements EnvironmentAware {
|
||||
return (this.enabled != null) ? this.enabled : this.bundle != null;
|
||||
}
|
||||
|
||||
public void copyDefaultsFrom(Ssl config) {
|
||||
if (this.enabled == null) {
|
||||
this.enabled = config.enabled;
|
||||
}
|
||||
if (this.bundle == null) {
|
||||
this.bundle = config.bundle;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void setEnabled(boolean enabled) {
|
||||
this.enabled = enabled;
|
||||
}
|
||||
@@ -531,6 +357,15 @@ public class GrpcClientProperties implements EnvironmentAware {
|
||||
this.bundle = bundle;
|
||||
}
|
||||
|
||||
/**
|
||||
* Copies the values from another instance.
|
||||
* @param other instance to copy values from
|
||||
*/
|
||||
public void copyValuesFrom(Ssl other) {
|
||||
this.enabled = other.enabled;
|
||||
this.bundle = other.bundle;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static class Health {
|
||||
@@ -538,7 +373,7 @@ public class GrpcClientProperties implements EnvironmentAware {
|
||||
/**
|
||||
* Whether to enable client-side health check for the channel.
|
||||
*/
|
||||
private Boolean enabled;
|
||||
private boolean enabled = false;
|
||||
|
||||
/**
|
||||
* Name of the service to check health on.
|
||||
@@ -546,10 +381,10 @@ public class GrpcClientProperties implements EnvironmentAware {
|
||||
private String serviceName;
|
||||
|
||||
public boolean isEnabled() {
|
||||
return this.enabled != null ? this.enabled : false;
|
||||
return this.enabled;
|
||||
}
|
||||
|
||||
public void setEnabled(Boolean enabled) {
|
||||
public void setEnabled(boolean enabled) {
|
||||
this.enabled = enabled;
|
||||
}
|
||||
|
||||
@@ -561,13 +396,13 @@ public class GrpcClientProperties implements EnvironmentAware {
|
||||
this.serviceName = serviceName;
|
||||
}
|
||||
|
||||
public void copyDefaultsFrom(Health config) {
|
||||
if (this.enabled == null) {
|
||||
this.enabled = config.enabled;
|
||||
}
|
||||
if (this.serviceName == null) {
|
||||
this.serviceName = config.serviceName;
|
||||
}
|
||||
/**
|
||||
* Copies the values from another instance.
|
||||
* @param other instance to copy values from
|
||||
*/
|
||||
public void copyValuesFrom(Health other) {
|
||||
this.enabled = other.enabled;
|
||||
this.serviceName = other.serviceName;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -51,7 +51,7 @@ class GrpcClientPropertiesTests {
|
||||
void withDefaultValues() {
|
||||
Map<String, String> map = new HashMap<>();
|
||||
// we have to at least bind one property or bind() fails
|
||||
map.put("spring.grpc.client.default-channel.max-inbound-message-size", "200");
|
||||
map.put("spring.grpc.client.default-channel.enable-keep-alive", "false");
|
||||
GrpcClientProperties properties = bindProperties(map);
|
||||
var defaultChannel = properties.getDefaultChannel();
|
||||
assertThat(defaultChannel.getAddress()).isEqualTo("static://localhost:9090");
|
||||
@@ -65,8 +65,8 @@ class GrpcClientPropertiesTests {
|
||||
assertThat(defaultChannel.getKeepAliveTimeout()).isEqualTo(Duration.ofSeconds(20));
|
||||
assertThat(defaultChannel.isEnableKeepAlive()).isFalse();
|
||||
assertThat(defaultChannel.isKeepAliveWithoutCalls()).isFalse();
|
||||
assertThat(defaultChannel.getMaxInboundMessageSize()).isEqualTo(DataSize.ofBytes(200));
|
||||
assertThat(defaultChannel.getMaxInboundMetadataSize()).isNull();
|
||||
assertThat(defaultChannel.getMaxInboundMessageSize()).isEqualTo(DataSize.ofBytes(4194304));
|
||||
assertThat(defaultChannel.getMaxInboundMetadataSize()).isEqualTo(DataSize.ofBytes(8192));
|
||||
assertThat(defaultChannel.getUserAgent()).isNull();
|
||||
assertThat(defaultChannel.isSecure()).isTrue();
|
||||
assertThat(defaultChannel.getSsl().isEnabled()).isFalse();
|
||||
@@ -146,37 +146,10 @@ class GrpcClientPropertiesTests {
|
||||
void withNoUserSpecifiedValues() {
|
||||
GrpcClientProperties properties = new GrpcClientProperties();
|
||||
var defaultChannel = properties.getDefaultChannel();
|
||||
var newChannel = new GrpcClientProperties.NamedChannel();
|
||||
newChannel.copyDefaultsFrom(defaultChannel);
|
||||
var newChannel = defaultChannel.copy();
|
||||
assertThat(newChannel).usingRecursiveComparison().isEqualTo(defaultChannel);
|
||||
}
|
||||
|
||||
@Test
|
||||
void withUserSpecifiedValuesAreRetained() {
|
||||
GrpcClientProperties properties = new GrpcClientProperties();
|
||||
var defaultChannel = properties.getDefaultChannel();
|
||||
var newChannel = new GrpcClientProperties.NamedChannel();
|
||||
newChannel.setAddress("static://my-server:9999");
|
||||
newChannel.setDefaultLoadBalancingPolicy("custom");
|
||||
newChannel.getHealth().setEnabled(true);
|
||||
newChannel.getHealth().setServiceName("custom-service");
|
||||
newChannel.setNegotiationType(NegotiationType.TLS);
|
||||
newChannel.setEnableKeepAlive(true);
|
||||
newChannel.setIdleTimeout(Duration.ofMinutes(1));
|
||||
newChannel.setKeepAliveTime(Duration.ofMinutes(4));
|
||||
newChannel.setKeepAliveTimeout(Duration.ofMinutes(6));
|
||||
newChannel.setKeepAliveWithoutCalls(true);
|
||||
newChannel.setMaxInboundMessageSize(DataSize.ofMegabytes(100));
|
||||
newChannel.setMaxInboundMetadataSize(DataSize.ofMegabytes(200));
|
||||
newChannel.setUserAgent("me");
|
||||
newChannel.setSecure(false);
|
||||
newChannel.getSsl().setEnabled(true);
|
||||
newChannel.getSsl().setBundle("custom-bundle");
|
||||
newChannel.copyDefaultsFrom(defaultChannel);
|
||||
assertThat(newChannel).usingRecursiveComparison().isNotEqualTo(defaultChannel);
|
||||
assertThat(newChannel).usingRecursiveComparison().isEqualTo(newChannel);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Nested
|
||||
|
||||
Reference in New Issue
Block a user