使用 Gremlin.net (V 3.3.2( 中的示例代码,我正在尝试连接到 Cosmos DB。我在执行任务时收到以下错误。Wait(( 执行:
"WebSocketException: 当状态代码为"101'时,服务器返回状态代码'200'"
任何想法为什么会失败?相同的代码适用于 Amazon Neptune。
var gremlinServer = new GremlinServer(hostname, port, enableSsl: true,username: "/dbs/" + database + "/colls/" + collection,password: authKey);
using (var gremlinClient = new GremlinClient(gremlinServer, new GraphSON2Reader(), new GraphSON2Writer(), GremlinClient.GraphSON2MimeType))
var task = gremlinClient.SubmitAsync<dynamic>(query.Value);
task.Wait();
正如汤姆所提到的,发布答案
创建客户端时,主机名应与 documentdb 不同,
类似于 sample.gremlin.cosmosdb.azure.com
代码将如下所示
private static GremlinServer GetGremlinServer(IConfigurationRoot builder)
{
var hostname = builder["cosmosDBConnection:gremlinEndpoint"];
var port = builder.GetValue<int>("cosmosDBConnection:gremlinPort", 443);
var authKey = builder["cosmosDBConnection:authKey"];
var databaseId = builder["cosmosDBConnection:databaseId"];
var graphId = builder["cosmosDBConnection:graphId"];
var gremlinServer = new GremlinServer(hostname, port, enableSsl: true, username: $"/dbs/{databaseId}/colls/{graphId}", password: authKey);
return gremlinServer;
}