diff --git a/src/Microsoft.Health.Fhir.CosmosDb/Features/Storage/FhirCosmosClientInitializer.cs b/src/Microsoft.Health.Fhir.CosmosDb/Features/Storage/FhirCosmosClientInitializer.cs index df1344f058..edd3458885 100644 --- a/src/Microsoft.Health.Fhir.CosmosDb/Features/Storage/FhirCosmosClientInitializer.cs +++ b/src/Microsoft.Health.Fhir.CosmosDb/Features/Storage/FhirCosmosClientInitializer.cs @@ -131,8 +131,16 @@ private CosmosClient CreateCosmosClientInternal(CosmosDataStoreConfiguration con new CosmosClientBuilder(host, _cosmosAccessTokenProviderFactory.Invoke().TokenCredential) : new CosmosClientBuilder(host, key); + if (configuration.ConnectionMode == ConnectionMode.Gateway) + { + builder.WithConnectionModeGateway(); + } + else + { + builder.WithConnectionModeDirect(enableTcpConnectionEndpointRediscovery: true); + } + builder - .WithConnectionModeDirect(enableTcpConnectionEndpointRediscovery: true) .WithCustomSerializer(new FhirCosmosSerializer(_logger)) .WithThrottlingRetryOptions(TimeSpan.FromSeconds(configuration.RetryOptions.MaxWaitTimeInSeconds), configuration.RetryOptions.MaxNumberOfRetries) .AddCustomHandlers(requestHandlers.ToArray());