Iain Brown
Iain Brown

Reputation: 1171

DocumentDB: using TCP connection with client lib > 1.9.0

With Microsoft.Azure.DocumentDB 1.9.0 the ConnectionProtocol variable in the ConnectionPolicy has been made obsolete with the comment:

"This property is deprecated. Please use ConnectionMode to choose communication protocol in conjution with connection endpoint mode."

We still set it to Tcp, and we set ConnectionMode to Direct. However, when doing a Fiddler capture of our app I can see the requests going to DocumentDb over HTTPS.

How do I force the lib to use the Tcp connection? Do I have to change the endpoint string? Ours is currently of the form:

https://mydocumentdb.documents.azure.com:443

as that's what Azure tells us to use. I'm really not clear what the comment means by "connection endpoint mode".

EDIT: By request, here's my connection code:

DocumentDbConnection ConnectionData = new DocumentDbConnection();

ConnectionPolicy ClientConnectionPolicy     = ConnectionPolicy.Default;
ClientConnectionPolicy.ConnectionMode       = ConnectionMode.Direct;
ClientConnectionPolicy.ConnectionProtocol   = Protocol.Tcp;

ConnectionData.DbClient = new DocumentClient( new Uri( DbEndpoint ), AccountKey, ClientConnectionPolicy );

// do initial connection upfront to avoid first-query latency
await ConnectionData.DbClient.OpenAsync();

DatabaseAccount DbAccount = await ConnectionData.DbClient.GetDatabaseAccountAsync();

Upvotes: 1

Views: 498

Answers (1)

Rajesh Nagpal
Rajesh Nagpal

Reputation: 1118

Direct TCP mode is only supported for any requests for server resources(like Documents). Requests for master resources(like document collection) will still go through the Gateway.

Can you elaborate what kind of requests you are seeing in fiddler? Note that the client initialization related requests will also go through gateway and any subsequent requests for server resources will be directed using TCP.

Are you using partitioned collections feature?

Note that we brought back the ConnectionProtocol in .NET SDK 1.9.2(which was marked as Obsolete earlier). If you were setting the Protocol to TCP and Mode to Direct even earlier it should work as expected. No need to change the endpoint string.

Regards, Rajesh

Upvotes: 1

Related Questions