Skip to content

Commit 0606cc8

Browse files
authored
add cosmos direct code configuration options (#4816)
1 parent f52ab01 commit 0606cc8

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

src/Microsoft.Health.Fhir.CosmosDb.Core/Configs/CosmosDataStoreConfiguration.cs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
// Licensed under the MIT License (MIT). See LICENSE in the repo root for license information.
44
// -------------------------------------------------------------------------------------------------
55

6+
using System;
67
using System.Collections.Generic;
78
using Microsoft.Azure.Cosmos;
89

@@ -30,6 +31,24 @@ public class CosmosDataStoreConfiguration
3031

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

34+
// Default value is indefinate, recommended value is 20m - 24 hours. Setting to 1 hour.
35+
public TimeSpan? IdleTcpConnectionTimeout { get; set; } = TimeSpan.FromHours(1);
36+
37+
// Default value is 5 seconds, recommended value is 1 second.
38+
public TimeSpan? OpenTcpConnectionTimeout { get; set; } = TimeSpan.FromSeconds(1);
39+
40+
// Default value is 30, recommended value is 30. Leaving null to use the SDK default.
41+
public int? MaxRequestsPerTcpConnection { get; set; }
42+
43+
// Default value is 65535, recommended value is 65535. Leaving null to use the SDK default.
44+
public int? MaxTcpConnectionsPerEndpoint { get; set; }
45+
46+
// Default value is PortReuseMode.ReuseUnicastPort, recommended value is PortReuseMode.ReuseUnicastPort. Leaving null to use the SDK default.
47+
public PortReuseMode? PortReuseMode { get; set; }
48+
49+
// Default value is true, recommended value is true. Leaving null to use the SDK default.
50+
public bool EnableTcpConnectionEndpointRediscovery { get; set; }
51+
3352
public ConsistencyLevel? DefaultConsistencyLevel { get; set; }
3453

3554
[System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2227:Collection properties should be read only", Justification = "This is a configuration class")]

src/Microsoft.Health.Fhir.CosmosDb/Features/Storage/FhirCosmosClientInitializer.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,13 @@ private CosmosClient CreateCosmosClientInternal(CosmosDataStoreConfiguration con
137137
}
138138
else
139139
{
140-
builder.WithConnectionModeDirect(enableTcpConnectionEndpointRediscovery: true);
140+
builder.WithConnectionModeDirect(
141+
idleTcpConnectionTimeout: configuration.IdleTcpConnectionTimeout,
142+
openTcpConnectionTimeout: configuration.OpenTcpConnectionTimeout,
143+
maxRequestsPerTcpConnection: configuration.MaxRequestsPerTcpConnection,
144+
maxTcpConnectionsPerEndpoint: configuration.MaxTcpConnectionsPerEndpoint,
145+
portReuseMode: configuration.PortReuseMode,
146+
enableTcpConnectionEndpointRediscovery: configuration.EnableTcpConnectionEndpointRediscovery);
141147
}
142148

143149
builder

0 commit comments

Comments
 (0)