Package net.devh.boot.grpc.client.config
Class GrpcChannelProperties
java.lang.Object
net.devh.boot.grpc.client.config.GrpcChannelProperties
The channel properties for a single named gRPC channel or service reference.
- Since:
- 5/17/16
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic class
A container with options for the channel's transport security. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected boolean
void
Copies the defaults from the given configuration.boolean
Gets the target address uri.Gets the default load balancing policy this channel should use.Get the connection timeout at application startup.Gets the default delay before we send a keepAlive.The default timeout for a keepAlives ping request.Gets the maximum message size allowed to be received by the channel.Sets the maximum size of metadata in bytes allowed to be received.Gets the negotiation type to use on the connection.Gets the options for transport security.Gets the time to wait for the channel to gracefully shutdown.Get custom User-Agent for the channel.int
hashCode()
boolean
Gets whether keepAlive is enabled.boolean
Gets whether keepAlive will be performed when there are no outstanding RPC on a connection.void
setAddress
(String address) Sets the target address uri for the channel.void
setAddress
(URI address) Set the address uri for the channel.void
setDefaultLoadBalancingPolicy
(String defaultLoadBalancingPolicy) Sets the default load balancing policy for this channel.void
setEnableKeepAlive
(Boolean enableKeepAlive) Sets whether keepAlive should be enabled.void
setImmediateConnectTimeout
(Duration immediateConnectTimeout) If set to a positive duration instructs the client to connect to the gRPC endpoint when the GRPC stub is created.void
setKeepAliveTime
(Duration keepAliveTime) The default delay before we send a keepAlives.void
setKeepAliveTimeout
(Duration keepAliveTimeout) The default timeout for a keepAlives ping request.void
setKeepAliveWithoutCalls
(Boolean keepAliveWithoutCalls) Sets whether keepAlive will be performed when there are no outstanding RPC on a connection.void
setMaxInboundMessageSize
(DataSize maxInboundMessageSize) Sets the maximum message size in bytes allowed to be received by the channel.void
setMaxInboundMetadataSize
(DataSize maxInboundMetadataSize) Sets the maximum size of metadata in bytes allowed to be received.void
setNegotiationType
(NegotiationType negotiationType) Sets the negotiation type to use on the connection.void
setShutdownGracePeriod
(Duration shutdownGracePeriod) Sets the time to wait for the channel to gracefully shutdown (completing all requests).void
setUserAgent
(String userAgent) Sets custom User-Agent HTTP header.toString()
-
Constructor Details
-
GrpcChannelProperties
public GrpcChannelProperties()
-
-
Method Details
-
getAddress
Gets the target address uri.- Returns:
- The address to connect to or null
- See Also:
-
setAddress
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 asdns:/
.- Parameters:
address
- The address to use for the channel or null to default to the fallback.- See Also:
-
setAddress
Sets the target address uri for the channel. The target uri must be in the format:schema:[//[authority]][/path]
. 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 asdns:/
.Examples
static://localhost:9090
(refers to exactly one IPv4 or IPv6 address, dependent on the jre configuration, it does not check whether there is actually someone listening on that network interface)static://10.0.0.10
static://10.0.0.10,10.11.12.11
static://10.0.0.10:9090,10.0.0.11:80,10.0.0.12:1234,[::1]:8080
dns:/localhost (might refer to the IPv4 or the IPv6 address or both, dependent on the system configuration, it does not check whether there is actually someone listening on that network interface)
dns:/example.com
dns:/example.com:9090
dns:///example.com:9090
discovery:/foo-service
discovery:///foo-service
unix:<relative-path>
(Additional dependencies may be required)unix://</absolute-path>
(Additional dependencies may be required)
- Parameters:
address
- The string representation of an uri to use as target address or null to use a fallback.- See Also:
-
getDefaultLoadBalancingPolicy
Gets the default load balancing policy this channel should use.- Returns:
- The default load balancing policy.
- See Also:
-
setDefaultLoadBalancingPolicy
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 theLoadBalancerRegistry
. By default this theround_robin
policy. Please note that this policy is different from the normal grpc-java default policypick_first
.- Parameters:
defaultLoadBalancingPolicy
- The default load balancing policy to use or null to use the fallback.
-
isEnableKeepAlive
public boolean isEnableKeepAlive()Gets whether keepAlive is enabled.- Returns:
- True, if keep alive should be enabled. False otherwise.
- See Also:
-
setEnableKeepAlive
Sets whether keepAlive should be enabled. Defaults to false.- Parameters:
enableKeepAlive
- True, to enable. False, to disable. Null, to use the fallback.
-
getKeepAliveTime
Gets the default delay before we send a keepAlive.- Returns:
- The default delay before sending keepAlives.
- See Also:
-
setKeepAliveTime
The default delay before we send a keepAlives. Defaults to5min
. Default unitSECONDS
. Please note that shorter intervals increase the network burden for the server. Cannot be lower than permitKeepAliveTime on server (default 5min).- Parameters:
keepAliveTime
- The new default delay before sending keepAlives, or null to use the fallback.- See Also:
-
setEnableKeepAlive(Boolean)
NettyChannelBuilder.keepAliveTime(long, TimeUnit)
-
getKeepAliveTimeout
The default timeout for a keepAlives ping request.- Returns:
- The default timeout for a keepAlives ping request.
- See Also:
-
setKeepAliveTimeout
The default timeout for a keepAlives ping request. Defaults to20s
. Default unitSECONDS
.- Parameters:
keepAliveTimeout
- The default timeout for a keepAlives ping request.- See Also:
-
setEnableKeepAlive(Boolean)
NettyChannelBuilder.keepAliveTimeout(long, TimeUnit)
-
isKeepAliveWithoutCalls
public boolean isKeepAliveWithoutCalls()Gets whether keepAlive will be performed when there are no outstanding RPC on a connection.- Returns:
- True, if keepAlives should be performed even when there are no RPCs. False otherwise.
- See Also:
-
setKeepAliveWithoutCalls
Sets whether keepAlive will be performed when there are no outstanding RPC on a connection. Defaults tofalse
.- Parameters:
keepAliveWithoutCalls
- whether keepAlive will be performed when there are no outstanding RPC on a connection.- See Also:
-
setEnableKeepAlive(Boolean)
NettyChannelBuilder.keepAliveWithoutCalls(boolean)
-
getShutdownGracePeriod
Gets the time to wait for the channel to gracefully shutdown. If set to a negative value, the channel waits forever. If set to0
the channel will force shutdown immediately. Defaults to30s
.- Returns:
- The time to wait for a graceful shutdown.
-
setShutdownGracePeriod
Sets the time to wait for the channel to gracefully shutdown (completing all requests). If set to a negative value, the channel waits forever. If set to0
the channel will force shutdown immediately. Defaults to30s
.- Parameters:
shutdownGracePeriod
- The time to wait for a graceful shutdown.
-
getMaxInboundMessageSize
Gets the maximum message size allowed to be received by the channel. If not set (null
) thengRPC's default
should be used. If set to-1
then it will use the highest possible limit (not recommended).- Returns:
- The maximum message size allowed or null if the default should be used.
- See Also:
-
setMaxInboundMessageSize
Sets the maximum message size in bytes allowed to be received by the channel. If not set (null
) then it will default togRPC's default
. If set to-1
then it will use the highest possible limit (not recommended).- Parameters:
maxInboundMessageSize
- The new maximum size in bytes allowed for incoming messages.-1
for max possible. Null to use the gRPC's default.- See Also:
-
getMaxInboundMetadataSize
Sets the maximum size of metadata in bytes allowed to be received. If not set (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-1
then it will use the highest possible limit (not recommended). Integer.MAX_VALUE disables the enforcement.- Returns:
- The maximum size of metadata in bytes allowed to be received or null if the default should be used.
- See Also:
-
setMaxInboundMetadataSize
Sets the maximum size of metadata in bytes allowed to be received. If not set (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-1
then it will use the highest possible limit (not recommended). Integer.MAX_VALUE disables the enforcement.- Parameters:
maxInboundMetadataSize
- The new maximum size of metadata in bytes allowed to be received.-1
for max possible. Null to use the gRPC's default.- See Also:
-
getNegotiationType
Gets the negotiation type to use on the connection.- Returns:
- The negotiation type that the channel will use.
- See Also:
-
setNegotiationType
Sets the negotiation type to use on the connection. Either ofTLS
(recommended),PLAINTEXT_UPGRADE
orPLAINTEXT
. Defaults to TLS.- Parameters:
negotiationType
- The negotiation type to use or null to use the fallback.
-
getImmediateConnectTimeout
Get the connection timeout at application startup.- Returns:
- connection timeout at application startup.
- See Also:
-
setImmediateConnectTimeout
If set to a positive duration instructs the client to connect to the gRPC endpoint when the GRPC stub is created. As a result the application startup will be slightly slower due to connection process being executed synchronously up to the maximum to connection timeout. If the connection fails, the stub will fail to create with an exception which in turn causes the application context startup to fail. Defaults to0
.- Parameters:
immediateConnectTimeout
- Connection timeout at application startup.
-
getUserAgent
Get custom User-Agent for the channel.- Returns:
- custom User-Agent for the channel.
- See Also:
-
setUserAgent
Sets custom User-Agent HTTP header.- Parameters:
userAgent
- Custom User-Agent.- See Also:
-
getSecurity
Gets the options for transport security.- Returns:
- The options for transport security.
-
copyDefaultsFrom
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.- Parameters:
config
- The config to copy the defaults from.
-
toString
-
equals
-
canEqual
-
hashCode
public int hashCode()
-