Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
544 views
in Technique[技术] by (71.8m points)

tinkerpop - How can I remotely connect to a JanusGraph server?

I want to use Java API to manipulate graph on a remote server, the server actually hosts in localhost. The code I use to connect server is:

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

But after I run the program, it throws exception like this:

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

So how can I connect to a remote JanusGraph server using Java API?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

The documentation I've found suggests to create an EmtpyGraph and get a remote traversal from that one:

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

where config is your a configuration object with the remote properties, e.g:

    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");

However, I've run into issues using JanusGraph specific features (for example committing a transaction) with this since the graph instance is the EmptyGraph itself, not a JanusGraph. So, try:

GraphTraversalSource g = JanusGraphFactory.open("inmemory").traversal().withRemote(config);

This will give you a traversal source to the remote gremlin-server, and you can do things like g.addV("vertexLabel")....; , g.tx().commit(); and so on.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

56.9k users

...