我尝试在cosmossdb模拟器中使用gremlin/java图形模式,但遇到了麻烦。
emulator已全部安装,正在运行,证书已导入我的java密钥库(我可以使用文档接口进行连接,这样我就知道它正在工作)。
emulator 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())
}
}
当我在调试器中观察时,生成器创建并连接客户机,但当我尝试提交客户机时,会得到以下stacktrace。
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 name,那么就相当于为图顶点等创建一个集合。
是否有人为本地cosmssdb仿真器提供了一个工作图形配置,以及我做了什么错误/遗漏了什么导致了此超时。附件是我开始发出客户机命令之前调试器的快照
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
但是,TimeoutException仍然发生。
我已经下载了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.
`
我仍然卡住了,不能让这个工作-我可以尝试下一步?
3条答案
按热度按时间hl0ma9xz1#
我试着用
gremlin console
连接我的Azure Cosmos DB
,效果不错。我的配置如下:
请注意
:>
那是在g.V()
,这在使用gremlin控制台时非常重要,这里提到了azurecosmosdb。然后,我按照你的配置尝试连接
Azure Cosmos DB Emulator
.经过多次尝试,我也遇到了和你一样的问题。
最后,我找到了这个反馈,似乎
Cosmos DB Emulator
当前不支持gremlin api。考虑到成本,我建议你用
Apache tinkerpop server
而不是Azure Cosmos DB Emulator
在开发阶段本地测试代码。测试完成后,转到azure cosmos db。此外,
Azure Cosmos DB Emulator
支架Graph API
这里提到的。更新答案
通过使用azurecosmosdb模拟器,您可以使用graphapi在本地进行开发和测试,而无需创建azure订阅或承担任何成本。当您对应用程序在模拟器中的工作方式感到满意时,可以切换到在云中使用azurecosmosdb帐户。
这篇文章可以在这里找到,但是在我研究了源代码之后,这里提到的仿真器支持的graph api只涉及
.Net
,不是指java或node.js。因此,azure cosmos db emulator似乎有缺陷,因为它可能无法更新azure cosmos db服务的最新更改。
希望对你有帮助。
2exbekwf2#
正如其他人所确定的,cosmosdb emulator在这个阶段不支持gremlin服务器仿真。
一种选择是使用
Microsoft.Azure.Graphs
.net sdk,它扩展了Microsoft.Azure.Documents.Client
支持gremlin查询。它能够直接连接到cosmosdb模拟器,并使用与cosmosdb gremlin服务器用于处理查询相同的实现。这里提供了用于graphs sdk的nuget包。
graph sdk教程/示例项目在这里。
关于将sdk连接到cosmosdb emulator的信息在这里
显然,这对于您的场景来说并不理想,但它将是本地验证gremlin查询的一个选项。
不幸的是,根据当前的时间表,向模拟器添加gremlin服务器支持对我们来说是一个小小的出路。
7eumitmz3#
此问题可能与apache tinkerpop库中的此缺陷有关,在该库中,它无法在与主机失去连接后重新连接到主机。
https://issues.apache.org/jira/browse/tinkerpop-2044