Class GrpcChannelProperties

java.lang.Object
net.devh.boot.grpc.client.config.GrpcChannelProperties

public class GrpcChannelProperties extends Object
The channel properties for a single named gRPC channel or service reference.
Since:
5/17/16
  • Constructor Details

    • GrpcChannelProperties

      public GrpcChannelProperties()
  • Method Details

    • getAddress

      public URI getAddress()
      Gets the target address uri.
      Returns:
      The address to connect to or null
      See Also:
    • setAddress

      public void setAddress(URI 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 dns:/.
      Parameters:
      address - The address to use for the channel or null to default to the fallback.
      See Also:
    • setAddress

      public void setAddress(String address)
      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 as dns:/.

      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

      public String getDefaultLoadBalancingPolicy()
      Gets the default load balancing policy this channel should use.
      Returns:
      The default load balancing policy.
      See Also:
    • setDefaultLoadBalancingPolicy

      public void setDefaultLoadBalancingPolicy(String 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 LoadBalancerRegistry. By default this the round_robin policy. Please note that this policy is different from the normal grpc-java default policy pick_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

      public void setEnableKeepAlive(Boolean enableKeepAlive)
      Sets whether keepAlive should be enabled. Defaults to false.
      Parameters:
      enableKeepAlive - True, to enable. False, to disable. Null, to use the fallback.
    • getKeepAliveTime

      public Duration getKeepAliveTime()
      Gets the default delay before we send a keepAlive.
      Returns:
      The default delay before sending keepAlives.
      See Also:
    • setKeepAliveTime

      public void setKeepAliveTime(Duration keepAliveTime)
      The default delay before we send a keepAlives. Defaults to 5min. Default unit SECONDS. 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:
    • getKeepAliveTimeout

      public Duration getKeepAliveTimeout()
      The default timeout for a keepAlives ping request.
      Returns:
      The default timeout for a keepAlives ping request.
      See Also:
    • setKeepAliveTimeout

      public void setKeepAliveTimeout(Duration keepAliveTimeout)
      The default timeout for a keepAlives ping request. Defaults to 20s. Default unit SECONDS.
      Parameters:
      keepAliveTimeout - The default timeout for a keepAlives ping request.
      See Also:
    • 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

      public void setKeepAliveWithoutCalls(Boolean keepAliveWithoutCalls)
      Sets whether keepAlive will be performed when there are no outstanding RPC on a connection. Defaults to false.
      Parameters:
      keepAliveWithoutCalls - whether keepAlive will be performed when there are no outstanding RPC on a connection.
      See Also:
    • getShutdownGracePeriod

      public Duration getShutdownGracePeriod()
      Gets the time to wait for the channel to gracefully shutdown. If set to a negative value, the channel waits forever. If set to 0 the channel will force shutdown immediately. Defaults to 30s.
      Returns:
      The time to wait for a graceful shutdown.
    • setShutdownGracePeriod

      public void setShutdownGracePeriod(Duration shutdownGracePeriod)
      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 to 0 the channel will force shutdown immediately. Defaults to 30s.
      Parameters:
      shutdownGracePeriod - The time to wait for a graceful shutdown.
    • getMaxInboundMessageSize

      public DataSize getMaxInboundMessageSize()
      Gets the maximum message size allowed to be received by the channel. If not set (null) then gRPC'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

      public void setMaxInboundMessageSize(DataSize maxInboundMessageSize)
      Sets the maximum message size in bytes allowed to be received by the channel. If not set (null) then it will default to gRPC'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

      public DataSize 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

      public void setMaxInboundMetadataSize(DataSize maxInboundMetadataSize)
      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

      public NegotiationType getNegotiationType()
      Gets the negotiation type to use on the connection.
      Returns:
      The negotiation type that the channel will use.
      See Also:
    • setNegotiationType

      public void setNegotiationType(NegotiationType negotiationType)
      Sets the negotiation type to use on the connection. Either of TLS (recommended), PLAINTEXT_UPGRADE or PLAINTEXT. Defaults to TLS.
      Parameters:
      negotiationType - The negotiation type to use or null to use the fallback.
    • getImmediateConnectTimeout

      public Duration getImmediateConnectTimeout()
      Get the connection timeout at application startup.
      Returns:
      connection timeout at application startup.
      See Also:
    • setImmediateConnectTimeout

      public 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. 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 to 0.
      Parameters:
      immediateConnectTimeout - Connection timeout at application startup.
    • getUserAgent

      public String getUserAgent()
      Get custom User-Agent for the channel.
      Returns:
      custom User-Agent for the channel.
      See Also:
    • setUserAgent

      public void setUserAgent(String userAgent)
      Sets custom User-Agent HTTP header.
      Parameters:
      userAgent - Custom User-Agent.
      See Also:
    • getSecurity

      public GrpcChannelProperties.Security getSecurity()
      Gets the options for transport security.
      Returns:
      The options for transport security.
    • copyDefaultsFrom

      public void copyDefaultsFrom(GrpcChannelProperties config)
      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

      public String toString()
      Overrides:
      toString in class Object
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • canEqual

      protected boolean canEqual(Object other)
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object