【问题标题】:Connecting to AWS Neptune with Gremlin GraphFactory使用 Gremlin GraphFactory 连接到 AWS Neptune
【发布时间】:2025-12-15 20:40:01
【问题描述】:

AWS documentation 上的示例展示了如何使用 Gremlin 连接到 AWS Neptune,如下所示:

Cluster.Builder builder = Cluster.build();
builder.addContactPoint("your-neptune-endpoint");
builder.port(8182);
builder.enableSsl(true);
builder.keyCertChainFile("SFSRootCAG2.pem");

Cluster cluster = builder.create();

GraphTraversalSource g = EmptyGraph.instance().traversal().withRemote(DriverRemoteConnection.using(cluster));

但是,我当前连接到通用 Gremlin 图的代码如下所示:

Configuration conf = new PropertiesConfiguration(...);
...    //Set configuration
Graph graph = GraphFactory.open(conf);

有谁知道如何将第二种方法与 GraphFactory 一起使用来连接到 Neptune?我无法在任何地方找到任何示例。

【问题讨论】:

    标签: java amazon-web-services gremlin tinkerpop3 amazon-neptune


    【解决方案1】:

    Neptune 不提供 Graph 实例,因为 Gremlin 不是在本地远程执行的。 GraphFactory 实际上仅适用于您想要创建 Graph 实例的情况。曾经有一个 RemoteGraph 允许这样做(尽管仍然在 TinkerPop 测​​试套件中使用),但这种方法早已被放弃并且不再推荐。

    您最初介绍的用于连接到 Neptune 等远程 Gremlin 提供程序的方法是建立GraphTraversalSource 的推荐方法。然而值得注意的是,从 3.3.5 开始,首选方法摆脱了 EmptyGraph 并允许您匿名实例化 GraphTraversalSource,如下所示:

    import static org.apache.tinkerpop.gremlin.process.traversal.AnonymousTraversalSource.traversal;
    
    GraphTraversalSource g = traversal().withRemote('conf/remote-graph.properties');
    

    withRemote() 的其他重载也应该看起来很熟悉。

    【讨论】:

    • 我们使用 Graph 的原因之一是我们想要读取 GraphML 文件(例如 graph.io(IoCore.graphml()).reader().batchSize(batchSize).create().readGraph(inputStream, graph);)。 GraphTraversalSource 可以做到这一点吗?
    • 它是从 3.4.0 开始的,但是今天才正式发布,我相当肯定 Neptune 还没有采用这种语法。您可以在此处查看有关新的g.io() 步骤的更多信息:tinkerpop.apache.org/docs/3.4.0/reference/#io-step 如果您需要将 GraphML 文件读入 Neptune,我想我建议将其读入 TinkerGraph,然后使用脚本将该数据复制到 Neptune。