【问题标题】:Timeout connection when using Gremlin to connect to Azure cosmossDB emulator使用 Gremlin 连接 Azure cosmossDB 模拟器时连接超时
【发布时间】:2017-09-04 16:10:33
【问题描述】:

我正在尝试将 Gremlin/Java 图形模式与 cosmossDB 模拟器结合使用,但遇到了麻烦。

模拟器已全部安装,正在运行并将证书导入我的 Java 密钥库(我可以使用文档界面进行连接,所以我知道它正在工作)。

模拟器 Web 控制台目前显示的是集合而不是图表。

我的简单代码(在 Groovy 脚本中)如下所示

Cluster cluster
Client client

try {
     def builder = Cluster.build()

        builder.addContactPoint("localhost")
        .port(8081)
        .protocol ("https")
        .keyPassword("C2y6yDjf5/R+ob0N8A7Cgv30VRDJIWEHLM+4QDU5DE2nQ9nDuVTqobD4b8mGGyPMbIZnqyMsEcaGQy67XIw/Jw==")
        .enableSsl(true)

        cluster = builder.create()
    } catch (Exception ex) {
    ex.printStackTrace()


}


client = cluster.connect()

String[] gremlinQueries = [
        "g.V().drop()",
        "g.addV('person').property('id', 'thomas').property('firstName', 'Thomas').property('age', 44)",
        "g.addV('person').property('id', 'mary').property('firstName', 'Mary').property('lastName', 'Andersen').property('age', 39)",
        "g.addV('person').property('id', 'ben').property('firstName', 'Ben').property('lastName', 'Miller')",
        "g.addV('person').property('id', 'robin').property('firstName', 'Robin').property('lastName', 'Wakefield')",
        "g.V('thomas').addE('knows').to(g.V('mary'))",
        "g.V('thomas').addE('knows').to(g.V('ben'))",
        "g.V('ben').addE('knows').to(g.V('robin'))",
        "g.V('thomas').property('age', 44)",
        "g.V().count()",
        "g.V().hasLabel('person').has('age', gt(40))",
        "g.V().hasLabel('person').order().by('firstName', decr)",
        "g.V('thomas').outE('knows').inV().hasLabel('person')",
        "g.V('thomas').outE('knows').inV().hasLabel('person').outE('knows').inV().hasLabel('person')",
        "g.V('thomas').repeat(out()).until(has('id', 'robin')).path()",
        "g.V('thomas').outE('knows').where(inV().has('id', 'mary')).drop()",
        "g.E().count()",
        "g.V('thomas').drop()"

]

for (gremlin in gremlinQueries) {
    ResultSet results = client.submit(gremlin);

    CompletableFuture<List<Result>> completableFutureResults = results.all()
    List<Result> resultList = completableFutureResults.get()

    for (Result result : resultList) {
        println(result.toString())
    }

}

当我在调试器中观看时,构建器创建并连接客户端,但是当我尝试客户端提交时,我得到以下堆栈跟踪。

Connected to the target VM, address: '127.0.0.1:59992', transport: 'socket'
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
Caught: java.lang.RuntimeException: java.lang.RuntimeException: java.util.concurrent.TimeoutException: Timed out while waiting for an available host - check the client configuration and connectivity to the server if this message persists
Disconnected from the target VM, address: '127.0.0.1:59992', transport: 'socket'
java.lang.RuntimeException: java.lang.RuntimeException: 
java.util.concurrent.TimeoutException: Timed out while waiting for an available host - check the client configuration and connectivity to the server if this message persists
    at org.apache.tinkerpop.gremlin.driver.Client.submit(Client.java:214)
    at org.apache.tinkerpop.gremlin.driver.Client.submit(Client.java:198)
    at org.apache.tinkerpop.gremlin.driver.Client$submit.call(Unknown Source)
    at playpen.TinkerPop-Example.run(TinkerPop-Example.groovy:64)
Caused by: java.lang.RuntimeException: java.util.concurrent.TimeoutException: Timed out while waiting for an available host - check the client configuration and connectivity to the server if this message persists
    at org.apache.tinkerpop.gremlin.driver.Client.submitAsync(Client.java:310)
    at org.apache.tinkerpop.gremlin.driver.Client.submitAsync(Client.java:242)
    at org.apache.tinkerpop.gremlin.driver.Client.submit(Client.java:212)

我有几个想法。我从以前的文档数据库原型中得到了一个“familyDB”,但我不知道用户的构建器中的 gremlin 配置方法是什么来表达这一点。

如果您想从头开始创建 dbs 名称,并且相当于为图形顶点创建集合等。

有没有人为本地 cosmossDB 模拟器提供工作图配置,我做错了什么/错过了什么导致此超时。附件是我开始发出客户端命令之前的调试器截图

PS - 尝试根据来自 GitHub 的 Azure graph zip 中的示例配置集群。

我的配置文件是这样的

hosts: [localhost] port: 8081 username: /dbs/familyDB/colls/FamilyCollection password: C2y6yDjf5/R+ob0N8A7Cgv30VRDJIWEHLM+4QDU5DE2nQ9nDuVTqobD4b8mGGyPMbIZnqyMsEcaGQy67XIw/Jw== connectionPool: { enableSsl: true} serializer: { className: org.apache.tinkerpop.gremlin.driver.ser.GraphSONMessageSerializerV1d0, config: { serializeResultToString: true }}

现在获取连接的修改代码如下

try {
    File config = new File("D:/Intellij - Azure/quickstart-java/graph/src/main/cosmossDB-config.yaml")
    assert config.exists()

    Cluster.Builder builder = Cluster.build(config)

     cluster = builder.create()
    println cluster.dump()
} catch (FileNotFoundException e) {
    e.printStackTrace()
    return
}

并且我已经从返回以下内容的集群实例中转储了运行时值

prop: maxWaitForConnection, with value 3000 prop: nioPoolSize, with value 8 prop: keepAliveInterval, with value 1800000 prop: loadBalancingStrategy, with value class org.apache.tinkerpop.gremlin.driver.LoadBalancingStrategy$RoundRobin prop: resultIterationBatchSize, with value 64 prop: port, with value 8081 prop: serializers, with value [application/json] prop: maxInProcessPerConnection, with value 4 prop: maxWaitForSessionClose, with value 3000 prop: reconnectInterval, with value 1000 prop: workerPoolSize, with value 16 prop: minInProcessPerConnection, with value 1 prop: class, with value class org.apache.tinkerpop.gremlin.driver.Cluster prop: sslEnabled, with value true prop: maxContentLength, with value 65536 prop: serializer, with value org.apache.tinkerpop.gremlin.driver.ser.GraphSONMessageSerializerV1d0@119020fb prop: factory, with value org.apache.tinkerpop.gremlin.driver.Cluster$Factory@3d9f6567 prop: closing, with value false prop: channelizer, with value org.apache.tinkerpop.gremlin.driver.Channelizer$WebSocketChannelizer prop: closed, with value false

但是 TimeoutExcption 仍然发生。

我已经下载了 gremlin 控制台并尝试:remote connect,但是当我运行命令时,我得到了这个,它警告你没有及时响应。

`gremlin> :remote connect tinkerpop.server conf/remote-cosmossDB.yaml
log4j:WARN No appenders could be found for logger (io.netty.util.internal.logging.InternalLoggerFactory).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.
==>Configured localhost/127.0.0.1:8081
gremlin>
gremlin> g.V()
No such property: g for class: groovysh_evaluate
Type ':help' or ':h' for help.
Display stack trace? [yN]
gremlin> :remote list
==>*0 - Gremlin Server - [localhost/127.0.0.1:8081]
gremlin> :remote console
==>All scripts will now be sent to Gremlin Server - [localhost/127.0.0.1:8081] - type ':remote console' to return to local mode
gremlin> g.V()
Host did not respond in a timely fashion - check the server status and submit again.
Type ':help' or ':h' for help.
Display stack trace? [yN]
gremlin> y
Host did not respond in a timely fashion - check the server status and submit again.
Type ':help' or ':h' for help.
`

我仍然卡住了,无法让它工作 - 接下来我可以尝试什么?

【问题讨论】:

  • 如果帮助任何人回答 - 尝试通过 conf 文件打开集群,而不是文件读取 hosts: [localhost] port: 8081 username: /dbs/familyDB/colls/FamilyCollection password: C2y6yDjf5/R+ob0N8A7Cgv30VRDJIWEHLM+4QDU5DE2nQ9nDuVTqobD4b8mGGyPMbIZnqyMsEcaGQy67XIw/Jw== connectionPool: { enableSsl: true} serializer: { className: org.apache.tinkerpop.gremlin.driver.ser.GraphSONMessageSerializerV1d0, config: { serializeResultToString: true }}

标签: java groovy graph azure-cosmosdb nosql


【解决方案1】:

我尝试使用gremlin console 连接我的Azure Cosmos DB,效果很好。

我的配置如下:

hosts: [jaygong.graphs.azure.com]
port: 443
username: /dbs/testdb/colls/jay
password: ****************
connectionPool: {enableSsl: true}
serializer: { className: org.apache.tinkerpop.gremlin.driver.ser.GraphSONMessageSerializerV1d0, config: { serializeResultToString: true }}

请注意g.V()前面的:&gt;,在使用Gremlin控制台时很重要,Azure Cosmos DB提到here

然后,我按照你的配置,尝试连接Azure Cosmos DB Emulator

hosts: [localhost]
port: 8081
username: /dbs/familyDB/colls/FamilyCollection
password: C2y6yDjf5/R+ob0N8A7Cgv30VRDJIWEHLM+4QDU5DE2nQ9nDuVTqobD4b8mGGyPMbIZnqyMsEcaGQy67XIw/Jw==
connectionPool: {
  enableSsl: true}
serializer: { className: org.apache.tinkerpop.gremlin.driver.ser.GraphSONMessageSerializerV1d0, config: { serializeResultToString: true }}

经过大量尝试,我也遇到了和你一样的问题。

终于找到了这个feedback,看来Cosmos DB Emulator目前不支持Gremlin API。

考虑到成本,我建议您在开发阶段使用Apache tinkerpop server 而不是Azure Cosmos DB Emulator 在本地测试您的代码。测试完成后,转到 Azure Cosmos DB。

另外,Azure Cosmos DB Emulator 支持Graph API,其中提到了here


更新答案

通过使用 Azure Cosmos DB 模拟器,您可以使用 Graph API 在本地开发和测试,无需创建 Azure 订阅或 产生任何费用。当您对您的应用程序感到满意时 在模拟器中工作,您可以切换到使用 Azure Cosmos DB 云中的帐户。

这段话可以在here找到。不过,经过我对source code的研究,这里提到的Emulator支持的Graph API仅指.Net, 不是指javanode.js

因此,Azure Cosmos DB 模拟器似乎存在缺陷,因为它可能无法与 Azure Cosmos DB 服务的最新更改保持同步。

希望对你有帮助。

【讨论】:

  • 也许只是这里的链接https://docs.microsoft.com/en-us/azure/cosmos-db/graph-introduction 的措辞说您可以使用 tinkerpop/gremlin 与 azure 交谈。页面上的这一行 By using the Azure Cosmos DB Emulator, you can use the Graph API to develop and test locally without creating an Azure subscription or incurring any costs 让我明白了 1 可以。
  • 可能 Graph API 是另一个微软的东西,而不是 tinkerpop/gremlin。因此模拟器还没有赶上现场蔚蓝服务。令人沮丧。
  • 您的配置看起来类似于为 live 配置的 github 项目。所以看起来我要去顶部必须使用 gremlin 服务器(用于 PoC)并希望重新配置以进行实时 - 令人沮丧
  • 我注意到模拟器在它启动的 Web 客户端中只显示文档而不是图形,但是另一个帖子 ID 不得不返回到 stackoverflow 说他们认为它确实如此。然而,证据就在布丁中。如果你的没有连接,而我的没有,这表明模拟器目前有缺陷。打扰
  • @WILLIAMWOODMAN 嗨,WILLIAM。请查看我的更新答案。
【解决方案2】:

正如其他人已经确定的那样,CosmosDB 模拟器现阶段不支持 gremlin 服务器模拟。

一种选择是使用Microsoft.Azure.Graphs .net SDK,它扩展了Microsoft.Azure.Documents.Client 以支持gremlin 查询。这能够直接连接到 CosmosDB 模拟器,并使用 CosmosDB gremlin 服务器用于处理查询的相同实现。

Graphs SDK 的 nuget 包可用here

Graph SDK 教程/示例项目是here

关于将 SDK 连接到 CosmosDB 模拟器的信息是 here

显然,鉴于您的情况,这并不理想,但它是在本地验证 gremlin 查询的一个选项。

不幸的是,根据当前的计划,将 Gremlin 服务器支持添加到模拟器中对我们来说是一条出路。

【讨论】:

  • 这真的很麻烦 - 我需要转入 .Net 而不是使用我的“自然”开发框架 groovy/java/spring。我知道 MS 本身并不自然地进入 java,但是允许模拟器通过 tinkerpop api 调用在 socket/io 级别工作(客户端恰好是 groovy/java 似乎很简单,而且是 azure 的一个很好的链接带有基于 java/spring 的开发人员的云。这为基于 java 的开发团队打开了 azure,以平等地协调 .net 或 java。同时,我将放弃 tinkerpop 服务器,我猜想使用图形 API 获得本地开发经验。
【解决方案3】:

此问题可能与 Apache Tinkerpop 库中的此缺陷有关,即在失去与主机的连接后无法重新连接到主机。

https://issues.apache.org/jira/browse/TINKERPOP-2044

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-09-27
    • 2011-10-19
    • 2016-05-28
    • 2015-09-08
    • 1970-01-01
    • 2022-01-21
    • 2014-07-24
    • 1970-01-01
    相关资源
    最近更新 更多