我尝试使用带有cosmossDB模拟器的gremlin / java图形模式,并遇到麻烦。
Emulator全部安装完毕,并且运行和证书被导入我的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())
}
}
构建器创建和客户端连接 - 当我在调试器中观看时,但是当我尝试客户端提交时,我得到以下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)
几个想法,我有一个&#34; familyDB&#34;从以前的文档DB原型。但是无法在用户的构建器中用gremlin配置方法来表达这一点。
如果你想从头开始创建dbs名称,等同于为图形顶点等创建一个集合。
所以有人为本地cosmossDB模拟器获得了一个工作图配置,以及我做错了/错过了什么导致这个超时。它变得简单,但我却想念它。在我开始发出客户端命令之前附加的是调试器的镜头
提前致谢
PS - 尝试在git hub的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.
`
仍然卡住了,无法让这个工作 - 来自有cosmossDb模拟器工作配置的人的任何想法?
答案 0 :(得分: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()
,在使用Gremlin控制台时,使用提及here的Azure Cosmos DB非常重要。
然后,我按照您的配置尝试连接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
支持提及here的Graph API
。
更新回答
通过使用Azure Cosmos数据库模拟器,您可以使用Graph API 在本地开发和测试,无需创建Azure订阅或 产生任何费用。当您对应用程序的满意度感到满意时 正在使用模拟器,您可以切换到使用Azure Cosmos DB 云中的帐户。
可以找到此段落here。但是,在我对source code的研究之后,此处提到的模拟器支持的图谱API仅指.Net
,
不是指java或node.js。
因此,似乎Azure Cosmos数据库模拟器存在缺陷,因为它可能无法与Azure Cosmos数据库服务的最新更改保持同步。
希望它对你有所帮助。
答案 1 :(得分:0)
正如其他人已经确定的那样,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服务器支持是一种方法。
答案 2 :(得分:0)
此问题可能与Apache Tinkerpop库中的此缺陷有关,在该缺陷中,失去与主机的连接后无法重新连接到主机。