Package com.azure.cosmos
Class DirectConnectionConfig
- java.lang.Object
-
- com.azure.cosmos.DirectConnectionConfig
-
public final class DirectConnectionConfig extends Object
Represents the connection config withConnectionMode.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
Constructors Constructor Description DirectConnectionConfig()
Constructor
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method 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 isDuration.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 130int
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 30Duration
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
setConnectionEndpointRediscoveryEnabled(boolean connectionEndpointRediscoveryEnabled)
Sets a value indicating whether Direct TCP connection endpoint rediscovery should be enabled.DirectConnectionConfig
setConnectTimeout(Duration connectTimeout)
Sets the connect timeout for direct client, represents timeout for establishing connections with an endpoint.DirectConnectionConfig
setIdleConnectionTimeout(Duration idleConnectionTimeout)
Sets the idle connection timeout Default value isDuration.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 130DirectConnectionConfig
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 30DirectConnectionConfig
setNetworkRequestTimeout(Duration networkRequestTimeout)
Sets the network request timeout interval (time to wait for response from network peer).String
toString()
-
-
-
Method Detail
-
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 ChannelChannelOption.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 ChannelChannelOption.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 isDuration.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 isDuration.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 toDuration.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 toDuration.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
-
-