Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose Cosmos Direct Mode Connection Config #4816

Merged
merged 1 commit into from
Feb 10, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// Licensed under the MIT License (MIT). See LICENSE in the repo root for license information.
// -------------------------------------------------------------------------------------------------

using System;
using System.Collections.Generic;
using Microsoft.Azure.Cosmos;

Expand Down Expand Up @@ -30,6 +31,24 @@ public class CosmosDataStoreConfiguration

public ConnectionMode ConnectionMode { get; set; } = ConnectionMode.Direct;

// Default value is indefinate, recommended value is 20m - 24 hours. Setting to 1 hour.
public TimeSpan? IdleTcpConnectionTimeout { get; set; } = TimeSpan.FromHours(1);

// Default value is 5 seconds, recommended value is 1 second.
public TimeSpan? OpenTcpConnectionTimeout { get; set; } = TimeSpan.FromSeconds(1);

// Default value is 30, recommended value is 30. Leaving null to use the SDK default.
public int? MaxRequestsPerTcpConnection { get; set; }

// Default value is 65535, recommended value is 65535. Leaving null to use the SDK default.
public int? MaxTcpConnectionsPerEndpoint { get; set; }

// Default value is PortReuseMode.ReuseUnicastPort, recommended value is PortReuseMode.ReuseUnicastPort. Leaving null to use the SDK default.
public PortReuseMode? PortReuseMode { get; set; }

// Default value is true, recommended value is true. Leaving null to use the SDK default.
public bool EnableTcpConnectionEndpointRediscovery { get; set; }

public ConsistencyLevel? DefaultConsistencyLevel { get; set; }

[System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2227:Collection properties should be read only", Justification = "This is a configuration class")]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,13 @@ private CosmosClient CreateCosmosClientInternal(CosmosDataStoreConfiguration con
}
else
{
builder.WithConnectionModeDirect(enableTcpConnectionEndpointRediscovery: true);
builder.WithConnectionModeDirect(
idleTcpConnectionTimeout: configuration.IdleTcpConnectionTimeout,
openTcpConnectionTimeout: configuration.OpenTcpConnectionTimeout,
maxRequestsPerTcpConnection: configuration.MaxRequestsPerTcpConnection,
maxTcpConnectionsPerEndpoint: configuration.MaxTcpConnectionsPerEndpoint,
portReuseMode: configuration.PortReuseMode,
enableTcpConnectionEndpointRediscovery: configuration.EnableTcpConnectionEndpointRediscovery);
}

builder
Expand Down
Loading