2017-09-04 117 views
0

我試圖在使用gremlin/java圖形模式與cosmossDB模擬器時出現問題並陷入困境。當使用gremlin連接到Azure 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模擬器工作圖配置,並且我做了什麼錯/錯過導致此超時。它有一些簡單但我錯過了它。附件是拍攝調試器之前,我開始issueing客戶機命令預先

image from the debugger before client.submit

感謝

PS - 試圖從git的轂配置羣集作爲每個樣品中天青圖表拉鍊。

我的配置文件看起來像這樣

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.ap[email protected]119020fb prop: factory, with value [email protected] prop: closing, with value false prop: channelizer, with value org.apache.tinkerpop.gremlin.driver.Channelizer$WebSocketChannelizer prop: closed, with value false

但是TimeoutExcption stil l發生。

我已經下載了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

如果可以幫助任何人來回答 - 試圖通過conf文件,而不是在文件中讀取'主機打開集羣:[本地主機] 端口:8081 用戶名:/ DBS/familyDB/colls/FamilyCollection 密碼:C2y6yDjf5/R + ob0N8A7Cgv30VRDJIWEHLM + 4QDU5DE2nQ9nDuVTqobD4b8mGGyPMbIZnqyMsEcaGQy67XIw/JW == 連接池:{ enableSsl:真正} 串行:{類名:org.apache.tinkerpop.gremlin.driver.ser.GraphSONMessageSerializerV1d0,配置:{serializeResultToString:真正}} ' –

回答

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()之前的:>,使用小鬼控制檯時,與提到here Azure的宇宙DB是很重要的。

enter image description 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 }} 

經過大量的嘗試,我也遇到了與您相同的問題。

enter image description here

最後,我發現這個feedback,並似乎Cosmos DB Emulator目前不支持小鬼API。

考慮到成本,我建議您在開發階段使用Apache tinkerpop server而不是Azure Cosmos DB Emulator在本地測試您的代碼。測試完成後,請轉至Azure Cosmos DB。

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


更新答案

通過使用Azure的宇宙模擬器DB,您可以使用圖形API來 開發和測試在本地,而不需要創建Azure訂閱或 承擔任何費用。如果您對應用程序 在模擬器中的工作狀態感到滿意,則可以切換到在雲中使用Azure Cosmos DB 帳戶。

這段話,可以發現這裏提到here。不過,我的研究爲source code後,模擬器支持圖形API只是指.Net, 不是指javanode.js

因此,Azure Cosmos數據庫仿真器似乎有缺陷,因爲它可能沒有及時更新Azure Cosmos數據庫服務的最新變化。

希望它可以幫助你。

+0

也許只是在這裏寫下'https:// docs.microsoft.com/en/us/zure/cosmos-db/graph-introduction'的鏈接,說你可以使用tinkerpop/gremlin與azure進行交談。頁面上的這一行'通過使用Azure Co smos數據庫模擬器,您可以使用Graph API在本地進行開發和測試,而無需創建Azure訂閱或承擔任何費用,這讓我明白了。 –

+0

也許Graph API是另一個微軟的東西,而不是tinkerpop/gremlin。因此這位助手並沒有趕上現場天藍色的服務。令人沮喪的。 –

+0

你的配置看起來類似於配置爲live的github項目。所以看起來我要去頂部必須使用gremlin服務器(對於PoC),並期望重新配置爲生活 - 令人沮喪 –

0

正如其他人已經確定的,CosmosDB仿真器在這個階段不支持gremlin服務器仿真。

一個選項是使用Microsoft.Azure.Graphs .net SDK,它擴展了Microsoft.Azure.Documents.Client以支持gremlin查詢。這可以直接連接到CosmosDB仿真器,並使用CosmosDB gremlin服務器用於處理查詢的相同實現。

Graphs SDK的nuget包可用here

圖SDK教程/示例項目是here。在連接到SDK模擬器CosmosDB

而且信息是here

顯然,這不是理想的給您的方案,但它是爲本地驗證小鬼查詢的選項。

不幸的是,在模擬器中添加Gremlin服務器支持對於我們來說有點基於當前時間表。

+0

這是一個botther真的 - 我需要轉移到.Net而不是使用groovy/java/spring這是我的'自然'開發框架。我知道MS本身並不是java本身,但允許模擬器使用tinkerpop API調用在socket/io級別工作(其中客戶端恰好是groovy/java似乎是一個沒有道理的,並且是一個很好的azure鏈接雲與Java /基於spring的開發人員一起工作,這使得基於java的開發團隊可以平等地協調.net或java平臺,同時我會退回tinkerpop服務器,我猜是否有圖形API的本地開發經驗。 –