2017-09-06 91 views
2

我在AWS上部署了dynamodb-janusgraph-storage-backend,我試圖弄清楚如何從Java連接到gremlin服務器。 我在我的項目中存在dynamodb-janusgraph-storage-backend的依賴項,但我不想使用作爲我的Java應用程序的一部分運行的gremlin服務器。我需要它獨立運行並將Java應用程序連接到該應用程序。Dynamodb-janusgraph-storage-backend從Java遠程連接

我查看了多個選項,比如使用Cluster(gremlin-java)和withRemote(gremlin-driver),但都有侷限性。我想使用Java Gremlin API,如果使用Cluster,我不能使用它。使用withRemote方法,我無法弄清楚如何初始化圖形實例。

gremlin文檔上的示例顯示EmptyGraph.instance(),如果我想使用JanusGraph API,則無法使用它。 我需要這部分與Janusgraph工作:

Cluster cluster = Cluster.open("conf/remote-objects.yaml"); // this has hosts and ports to gremlin server running in AWS 
graph = EmptyGraph.instance(); 
graph.traversal().withRemote(DriverRemoteConnection.using(cluster)) 

我需要對象是JanusGraph類型,所以我可以用openManagement()等方法。此外,使用高級圖形類型,我不能添加新的頂點。我需要能夠從我的java代碼創建,獲取和更新。

回答

1

目前無法通過遠程驅動程序調用JanusGraph架構API。如果您不想從應用程序打開JanusGraph實例,則必須將該架構構建爲字符串,並使用Client submit將其發送到Gremlin服務器。您仍然可以使用traversal source with remote driver來構建和查詢圖形。

Cluster cluster = Cluster.open("conf/remote-objects.yaml"); 

// use client to create the schema 
Client client = cluster.connect(); 
String schema = "mgmt=graph.openManagement();"; 
schema += "mgmt.makeVertexLabel(\"person\").make();"; 
schema += "mgmt.makeVertexLabel(\"person\");"; 
schema + "mgmt.makePropertyKey(\"name\").dataType(String.class).make();" 
schema += "mgmt.commit(); true"; 
CompletableFuture<List<Result>> results = client.submit(schema).all(); 

// use traversals only to interact with the graph 
Graph graph = EmptyGraph.instance(); 
GraphTraversalSource g = graph.traversal().withRemote(DriverRemoteConnection.using(cluster)); 
Vertex v = g.addV("person").property("name", "pepe").next(); 
List<Vertex> vlist = g.V().toList(); 
+0

您將如何創建頂點之間的邊? 我試過但沒有工作: gV()。has(「name」,「pepe」)。addE(「created」).to(gV()。has(「name」,「anotherUser」 ).next()) .property(「CREATED_AT」,LocalDateTime.now()。toEpochSecond(ZoneOffset.UTC)); – monali01

+2

我知道了 - 這工作: gV()。has(「name」,「pepe」)。as(「a」)。V() .has(「name」,「anotherUser」)。addE創建).from(「a」) .property(「CREATED_AT」,LocalDateTime.now()。toEpochSecond(ZoneOffset.UTC))。next(); – monali01

+0

我認爲我的問題是無法添加頂點和邊緣,我可以通過GraphTraversalSource來完成,因此目前該解決方案將起作用。我將通過控制檯或一個時間代碼創建模式和索引,所以如果我必須使用客戶端,它應該沒問題。 – monali01