gpt4 book ai didi

tinkerpop - 如何远程连接到JanusGraph服务器?

转载 作者:行者123 更新时间:2023-12-04 05:36:32 30 4
gpt4 key购买 nike

我想使用Java API来操作远程服务器上的图形,该服务器实际上位于localhost中。我用来连接服务器的代码是:

JanusGraphFactory.Builder b = JanusGraphFactory.build();
b.set("hosts", "[localhost]");
JanusGraph graph = b.open();

但是在我运行程序之后,它会引发如下异常:

Exception in thread "main" java.lang.IllegalStateException: Need to set configuration value: root.storage.backend



那么如何使用Java API连接到远程JanusGraph服务器?

最佳答案

我发现的文档建议创建一个EmtpyGraph并从该对象中进行远程遍历:

EmptyGraph.instance().traversal().withRemote(config);

其中config是您的具有远程属性的配置对象,例如:
    config.setProperty("clusterConfiguration.hosts", HOST);
config.setProperty("clusterConfiguration.port", PORT);
config.setProperty("clusterConfiguration.serializer.className", "org.apache.tinkerpop.gremlin.driver.ser.GryoMessageSerializerV1d0");
config.setProperty("clusterConfiguration.serializer.config.ioRegistries", ioRegistries); // (e.g. [ org.janusgraph.graphdb.tinkerpop.JanusGraphIoRegistry) ]
config.setProperty("gremlin.remote.remoteConnectionClass", "org.apache.tinkerpop.gremlin.driver.remote.DriverRemoteConnection");
config.setProperty("gremlin.remote.driver.sourceName", "g");

但是,由于图形实例是EmptyGraph本身而不是JanusGraph,因此在使用JanusGraph特定功能(例如提交事务)时遇到了问题。因此,请尝试:
GraphTraversalSource g = JanusGraphFactory.open("inmemory").traversal().withRemote(config);

这将为您提供到远程gremlin服务器的遍历源,并且您可以执行g.addV(“vertexLabel”)....;之类的操作。 ,g.tx()。commit();等等。

关于tinkerpop - 如何远程连接到JanusGraph服务器?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45673861/

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