【问题标题】:Azure Cosmos DB using Gremlin.Net - Error submitting query使用 Gremlin.Net 的 Azure Cosmos DB - 提交查询时出错
【发布时间】:2018-04-09 17:58:27
【问题描述】:

使用 Gremlin.net (V 3.3.2) 中的示例代码,我正在尝试连接到 Cosmos DB。 task.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();

【问题讨论】:

  • 主机名与 Document API 不同,应该类似于 your-account.gremlin.cosmosdb.azure.com
  • 谢谢!这解决了问题。此处的 Microsoft 示例 github.com/Azure-Samples/azure-cosmos-db-dotnet-graphexplorer 的主机名错误。
  • @RickJN 您可以在此处添加答案以帮助更多社区。​​span>

标签: azure azure-cosmosdb


【解决方案1】:

正如汤姆所说,发布答案

当您创建客户端时,主机名应该与 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;
 }

【讨论】:

  • 另请注意,如果您使用 Microsoft 快速入门从 Azure 仪表板生成 Gremlin 控制台,则截至今天主机名不正确。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-05-20
  • 1970-01-01
  • 1970-01-01
  • 2019-06-29
  • 1970-01-01
相关资源
最近更新 更多