DirectConnectionConfig Class

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

public final class DirectConnectionConfig

Represents the connection config with 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 Summary

Constructor Description
DirectConnectionConfig()

Constructor

Method Summary

Modifier and Type Method and Description
Duration getConnectTimeout()

Gets the connect timeout for direct client, represents timeout for establishing connections with an endpoint.

static DirectConnectionConfig getDefaultConfig()

Gets the default DIRECT connection configuration.

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.

Duration getIdleEndpointTimeout()

Gets the idle endpoint timeout Default value is 1 hour.

int getMaxConnectionsPerEndpoint()

Gets the max connections per endpoint This represents the size of connection pool for a specific endpoint Default value is 130

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

Duration getNetworkRequestTimeout()

Gets the network request timeout interval (time to wait for response from network peer).

boolean isConnectionEndpointRediscoveryEnabled()

Gets a value indicating whether Direct TCP connection endpoint rediscovery is enabled.

DirectConnectionConfig setConnectTimeout(Duration connectTimeout)

Sets the connect timeout for direct client, represents timeout for establishing connections with an endpoint.

DirectConnectionConfig setConnectionEndpointRediscoveryEnabled(boolean connectionEndpointRediscoveryEnabled)

Sets a value indicating whether Direct TCP connection endpoint rediscovery should be enabled.

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.

DirectConnectionConfig setIdleEndpointTimeout(Duration idleEndpointTimeout)

Sets the idle endpoint timeout Default value is 1 hour.

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

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

DirectConnectionConfig setNetworkRequestTimeout(Duration networkRequestTimeout)

Sets the network request timeout interval (time to wait for response from network peer).

String toString()

Methods inherited from java.lang.Object

Constructor Details

DirectConnectionConfig

public DirectConnectionConfig()

Constructor

Method Details

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

getDefaultConfig

public static DirectConnectionConfig getDefaultConfig()

Gets the default DIRECT connection configuration.

Returns:

the default direct connection configuration.

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

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

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

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

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

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 enabled.

Returns:

true if Direct TCP connection endpoint rediscovery is enabled; false otherwise.

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:

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 enabled.

Parameters:

connectionEndpointRediscoveryEnabled - true if connection endpoint rediscovery is enabled; false otherwise.

Returns:

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:

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:

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:

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:

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 ?1s 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:

toString

public String toString()

Overrides:

DirectConnectionConfig.toString()

Applies to