示例代码(JAVA):
Cluster cluster = Cluster.open(yml.getFile());
DriverRemoteConnection driver = DriverRemoteConnection.using(cluster, "graph_traversal");
GraphTraversalSource allGraph = AnonymousTraversalSource.traversal().withRemote(driver);
// Using Io --> generate a file in server-side
allGraph.Io("File.json").write().iterate()
// Using GraphSONWriter
GraphSONMapper mapper = GraphSONMapper.build().addRegistry(JanusGraphIoRegistry.instance()).version(GraphSONVersion.V3_0).create();
GraphSONWriter writer = GraphSONWriter.build().mapper(mapper).create();
ByteArrayOutputStream output = new ByteArrayOutputStream();
// output --> "" (Empty)
writer.writeGraph(output, allGraph.getGraph());
// output --> "~" (Only Vertex Ids)
writer.writeVertices(output, allGraph.V());
我正在尝试通过远程服务器将图导出为GraphSON。但是IO步骤不提供用于远程导出的功能。使用GraphSonWriter,它无法正确写入内容。如何在远程服务器环境中以GraphSON格式导出图形?
谢谢。
直到TinkerPop在g.io()
步骤附近为远程环境提供更好的支持,它仍然仅适用于在执行Gremlin的本地进行读写。如果要将图形从远程源导出到GraphSON,则根据您使用的图形有一些选项。您用JanusGraph标记了这个问题,所以我将重点关注它。您可以:
GraphSONWriter
,然后向writeGraph()
提供OutputStream
,该C0将写入byte[]
或String
,然后将其返回给客户端。 g.E().subgraph('sg').cap('sg')
并将整个图复制到子图即可。这将在客户端上产生一个TinkerGraph
,然后您可以根据需要使用io()
将图形本地写入GraphSON。这仅在您使用Java时才有效,因为其他语言尚不支持subgraph()
。JanusGraph
实例,然后io()
将照常工作。