Johannes
Johannes

Reputation: 314

Use Neo4jGraph.open() or GraphFactory.open() to access remote Neo4j database in Java

I'm using the Tinkerpop's GraphFactory.open(Configuration configuration) Java command to access a Neo4j database.

A working minimum example is:

Configuration configuration = new BaseConfiguration();
configuration.addProperty("gremlin.graph", "org.apache.tinkerpop.gremlin.neo4j.structure.Neo4jGraph");
configuration.addProperty("gremlin.neo4j.directory", "tmp/neo4j");
GraphFactory.open(configuration);

However, I want to connect to a remote Neo4j database instead. So I need something like

configuration.addProperty("gremlin.neo4j.directory", "ip:port");

which results in an exception:

java.lang.RuntimeException: java.io.IOException: Unable to create directory path [C:\Users\backend\192.168.56.102:7474] for Neo4j store.

Seems like Neo4j tries to access the ip:port like a file path... Thanks in advance for your help.

Upvotes: 1

Views: 995

Answers (2)

Johannes
Johannes

Reputation: 314

Thanks to stephen mallette, I found a solution.

From Neo4j 3.0, the Bolt protocol is enabled by default.

So I used neo4j-gremlin-bolt to connect to my Neo4j remote database via Java as follows:

Driver driver = GraphDatabase.driver("bolt://<IP>", AuthTokens.basic("user", "pass"));
Graph graph = new Neo4JGraph(driver, vertexIdProvider, edgeIdProvider));

Read about the ID providers at the link provided.

Upvotes: 1

stephen mallette
stephen mallette

Reputation: 46226

As you've found, that approach won't work. Neo4jGraph is designed to work as embedded and thus requires either a file system location for the database files or it can become a node in a HA cluster which is described here.

Your other choice is to use a third-party implementation that uses the Bolt protocol, neo4j-gremlin-bolt. That should do what you want.

Upvotes: 1

Related Questions