Gremlin Java 3.4 withRemote 已弃用

Gremlin Java 3.4 withRemote deprecated

所以在 gremlin java 3.4 之前,我使用以下代码连接到远程图形:

Cluster.Builder builder = Cluster.build();
builder.addContactPoint(GREMLIN_SERVER);
builder.port(GREMLIN_PORT);
builder.serializer(new GryoMessageSerializerV1d0());
cluster = builder.create();
g = EmptyGraph.instance().traversal().withRemote(DriverRemoteConnection.using(cluster, GRAPH_NAME));
return g;

我已将 JanusGraph 更新到版本 0.4.0 并尝试使用 gremlin java 3.4.3,我发现每个 withRemote 方法现在都已弃用。

gremlin 服务器配置为使用 JanusGraphManager 和 ConfigurationManagementGraph。并在启动时运行以下脚本:

def globals = [:]


def getGraph() {
    def graphNames =  ConfiguredGraphFactory.getGraphNames();
    def graphMaps = [:];
    for (graphName in graphNames) {
        def g = ConfiguredGraphFactory.open(graphName);
        graphMaps.put(graphName, g.traversal())
    }
    return graphMaps;
}

globals << getGraph()

我似乎找不到从 java 获取遍历源的新正确方法。

升级图形数据库依赖项时,查看 TinkerPop 升级文档总是有帮助的。 TinkerPop 通常会尝试指出弃用和修改的做事方式。在您的情况下,升级文档中的这一点 here 就是您所需要的。具体来说,您需要使用新的 AnonymousTraversalSource 而不是 EmptyGraph 来生成您的 GraphTraversalSource:

GraphTraversalSource g = traversal().withRemote('conf/remote-graph.properties');

请注意,javadoc 也会帮助您指出这个方向。