Class DirectConnectionConfig

java.lang.Object
com.azure.cosmos.DirectConnectionConfig

public final class DirectConnectionConfig extends Object
Represents the connection config with ConnectionMode.DIRECT associated with Cosmos Client in the Azure Cosmos DB database service. For performance tips on how to optimize Direct connection configuration, refer to performance tips guide: Performance tips guide
  • Constructor Details

    • DirectConnectionConfig

      public DirectConnectionConfig()
      Constructor
  • Method Details

    • isConnectionEndpointRediscoveryEnabled

      public boolean isConnectionEndpointRediscoveryEnabled()
      Gets a value indicating whether Direct TCP connection endpoint rediscovery is enabled.

      The connection endpoint rediscovery feature is designed to reduce and spread-out latency spikes that may occur during maintenance operations. By default, connection endpoint rediscovery is disabled.

      Returns:
      true if Direct TCP connection endpoint rediscovery is enabled; false otherwise.
    • setConnectionEndpointRediscoveryEnabled

      public DirectConnectionConfig setConnectionEndpointRediscoveryEnabled(boolean connectionEndpointRediscoveryEnabled)
      Sets a value indicating whether Direct TCP connection endpoint rediscovery should be enabled.

      The connection endpoint rediscovery feature is designed to reduce and spread-out latency spikes that may occur during maintenance operations. By default, connection endpoint rediscovery is disabled.

      Parameters:
      connectionEndpointRediscoveryEnabled - true if connection endpoint rediscovery is enabled; false otherwise.
      Returns:
      the DirectConnectionConfig.
    • getDefaultConfig

      public static DirectConnectionConfig getDefaultConfig()
      Gets the default DIRECT connection configuration.
      Returns:
      the default direct connection configuration.
    • getConnectTimeout

      public Duration getConnectTimeout()
      Gets the connect timeout for direct client, represents timeout for establishing connections with an endpoint. Configures timeout for underlying Netty Channel ChannelOption.CONNECT_TIMEOUT_MILLIS By default, the connect timeout is 5 seconds.
      Returns:
      direct connect timeout
    • setConnectTimeout

      public DirectConnectionConfig setConnectTimeout(Duration connectTimeout)
      Sets the connect timeout for direct client, represents timeout for establishing connections with an endpoint. Configures timeout for underlying Netty Channel ChannelOption.CONNECT_TIMEOUT_MILLIS By default, the connect timeout is 5 seconds.
      Parameters:
      connectTimeout - the connection timeout
      Returns:
      the DirectConnectionConfig
    • getIdleConnectionTimeout

      public Duration getIdleConnectionTimeout()
      Gets the idle connection timeout for direct client Default value is Duration.ZERO Direct client doesn't close a single connection to an endpoint by default unless specified.
      Returns:
      idle connection timeout
    • setIdleConnectionTimeout

      public DirectConnectionConfig setIdleConnectionTimeout(Duration idleConnectionTimeout)
      Sets the idle connection timeout Default value is Duration.ZERO Direct client doesn't close a single connection to an endpoint by default unless specified.
      Parameters:
      idleConnectionTimeout - idle connection timeout
      Returns:
      the DirectConnectionConfig
    • getIdleEndpointTimeout

      public Duration getIdleEndpointTimeout()
      Gets the idle endpoint timeout Default value is 1 hour. If set to Duration.ZERO, idle endpoint check will be disabled. If there are no requests to a specific endpoint for idle endpoint timeout duration, direct client closes all connections to that endpoint to save resources and I/O cost.
      Returns:
      the idle endpoint timeout
    • setIdleEndpointTimeout

      public DirectConnectionConfig setIdleEndpointTimeout(Duration idleEndpointTimeout)
      Sets the idle endpoint timeout Default value is 1 hour. If set to Duration.ZERO, idle endpoint check will be disabled. If there are no requests to a specific endpoint for idle endpoint timeout duration, direct client closes all connections to that endpoint to save resources and I/O cost.
      Parameters:
      idleEndpointTimeout - the idle endpoint timeout
      Returns:
      the DirectConnectionConfig
    • getMaxConnectionsPerEndpoint

      public int getMaxConnectionsPerEndpoint()
      Gets the max connections per endpoint This represents the size of connection pool for a specific endpoint Default value is 130
      Returns:
      the max connections per endpoint
    • setMaxConnectionsPerEndpoint

      public DirectConnectionConfig setMaxConnectionsPerEndpoint(int maxConnectionsPerEndpoint)
      Sets the max connections per endpoint This represents the size of connection pool for a specific endpoint Default value is 130
      Parameters:
      maxConnectionsPerEndpoint - the max connections per endpoint
      Returns:
      the DirectConnectionConfig
    • getMaxRequestsPerConnection

      public int getMaxRequestsPerConnection()
      Gets the max requests per connection This represents the number of requests that will be queued on a single connection for a specific endpoint Default value is 30
      Returns:
      the max requests per endpoint
    • setMaxRequestsPerConnection

      public DirectConnectionConfig setMaxRequestsPerConnection(int maxRequestsPerConnection)
      Sets the max requests per connection This represents the number of requests that will be queued on a single connection for a specific endpoint Default value is 30
      Parameters:
      maxRequestsPerConnection - the max requests per endpoint
      Returns:
      the DirectConnectionConfig
    • getNetworkRequestTimeout

      public Duration getNetworkRequestTimeout()
      Gets the network request timeout interval (time to wait for response from network peer). Default value is 5 seconds
      Returns:
      the network request timeout interval
    • setNetworkRequestTimeout

      public DirectConnectionConfig setNetworkRequestTimeout(Duration networkRequestTimeout)
      Sets the network request timeout interval (time to wait for response from network peer). Default value is 5 seconds. It only allows values ≥5s and ≤10s. (backend allows requests to take up-to 5 seconds processing time - 5 seconds buffer so 10 seconds in total for transport is more than sufficient). Attention! Please adjust this value with caution. This config represents the max time allowed to wait for and consume a service response after the request has been written to the network connection. Setting a value too low can result in having not enough time to wait for the service response - which could cause too aggressive retries and degrade performance. Setting a value too high can result in fewer retries and reduce chances of success by retries.
      Parameters:
      networkRequestTimeout - the network request timeout interval.
      Returns:
      the DirectConnectionConfig
    • toString

      public String toString()
      Overrides:
      toString in class Object