gpt4 book ai didi

java - dynamodb-janusgraph-storage-backend 从 Java 远程连接

转载 作者:塔克拉玛干 更新时间:2023-11-02 19:49:31 24 4
gpt4 key购买 nike

我在 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() 和其他方法。此外,使用高级图形类型,我无法添加新的顶点。我需要能够从我的 Java 代码中创建、获取和更新。

最佳答案

目前无法通过远程驱动程序调用 JanusGraph Schema 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();

关于java - dynamodb-janusgraph-storage-backend 从 Java 远程连接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46066659/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com