首页 > 解决方案 > Gremlin Java 3.4 withRemote 已弃用

问题描述

所以在 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 获取遍历源的新正确方法。

标签: gremlinjanusgraphgremlin-server

解决方案


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

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

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


推荐阅读