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?
Try this:
Here is a simple way:
graph = JanusGraphFactory.open("conf/janusgraph-cassandra-solr.properties") juno = graph.addVertex() //Automatically opens a new transaction juno.property("name", "juno") graph.tx().commit() //Commits transaction
Janus User Doc
Janus uses an existing storage solution like cassandra, hbase, berkelydb to store data.
You can connect by 2 ways: 1 - Connect to the remote gremlin server and execute traversal/queries remotely. This is by using the Cluster and EmptyGraph of tinkerpop gremlin 2 - Connect directly from your application using the technique i suggested int his post above.
Pros/Cons of connecting to the remote gremlin server
Pros
Cons
BY connecting directly from your client code (avoiding the remote connection) you get much more control.
Also, you can use the JanusGraph instance directly in your code, which is still gremlin complaint, to take full advantage of the JanusGraph API's.
Check RemoteGraph in janusgraph examples.
You can find under Class RemoteGraphApp how you can connect to remote janusgraph server (Cluster).
where the cluster config file contains:
The documentation I've found suggests to create an EmtpyGraph and get a remote traversal from that one:
where config is your a configuration object with the remote properties, e.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:
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.