使用Java远程连接dynamodb-janusgraph存储后端

3
我在AWS上部署了dynamodb-janusgraph-storage-backend,并尝试找出如何从Java连接到gremlin服务器。我在项目中有dynamodb-janusgraph-storage-backend的sbt依赖项,但我不想使用作为java应用程序一部分运行的gremlin服务器。我需要它独立运行,并将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))

我需要将graph对象转换为JanusGraph类型,这样我才能使用openManagement()和其他方法。同时使用高级Graph类型无法添加新的顶点。我需要在我的Java代码中能够创建、获取、更新数据。
1个回答

1

目前无法通过远程驱动程序调用JanusGraph模式API。如果您不想从应用程序中打开JanusGraph实例,则必须将模式构建为字符串,并使用客户端提交将其发送到Gremlin服务器。您仍然可以使用带有远程驱动程序的遍历源来构建和查询图。

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();

1
你如何在两个顶点之间创建边缘?我尝试了这个但没有成功:g.V().has("name", "pepe").addE("created") .to(g.V().has("name", "anotherUser").next()) .property("CREATED_AT", LocalDateTime.now().toEpochSecond(ZoneOffset.UTC)); - monali01
2
我明白了,这个可行:g.V().has("name", "pepe").as("a").V() .has("name", "anotherUser").addE(created).from("a") .property("CREATED_AT", LocalDateTime.now().toEpochSecond(ZoneOffset.UTC)).next(); - monali01
我认为我的问题是无法添加顶点和边,但我可以通过GraphTraversalSource来实现,所以目前这个解决方案可以工作。我将通过控制台或一次性代码创建模式和索引,因此如果我必须使用客户端进行操作,那也应该没问题。 - monali01
看起来我不能使用“String schema =“mgmt=graph.openManagement();”;”图形是Graph类型,它没有那个方法。 - monali01

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接