Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Connecting to remote neo4j using Java API

Tags:

neo4j

I'm writing a test app that makes use of neo4j. I've been trying to follow a few tutorials, reading online, and also checking the documentation, and the most common way of making use of the Java API made available is to use an embedded neo4j.

Now, for multiple reasons this will not work for me. (Eg. server on different machine, etc.)

I'm using :

"org.neo4j" % "neo4j" % "2.1.5",
"org.neo4j" % "neo4j-rest-graphdb" % "2.0.1",

And connecting to neo4j this way :

GraphDatabaseService gds = new RestGraphDatabase("http://neo4jserver_address:7474/db/data");

As anwsered before on another SO post, the RestGraphDatabase is not a complete implementation of GraphDatabaseService , which leads to all sorts of trouble when trying to use , for example, other libs such as :

"com.graphaware.neo4j" % "timetree" % "2.1.5.25.18",

Also, the fact that RestGraphDatabase doesn't allow usage of GlobalGraphOperations because of that same problem.

I've tried seaching the official documentation I've found and again, the examples given are for embedded DB.

My question is if anyone knows of the correct way to connect to a remote neo4j server the right way and where in the documentation I can read about this bit?

Also, no I'm not using neo4j HA , although I have a 1 year testing license.

PS - connection over REST is not required. Protocol is irrelevant, what the question is is how to connect to a remote neo4j server (over whatever protocol) using the API and ending up with a proper, full implementation of GraphDatabaseService

like image 924
SysHex Avatar asked Nov 25 '14 16:11

SysHex


1 Answers

I know that what you really want is a GraphDatabaseService object that's attached to a RESTful endpoint. That's what your code says, but based on my best understanding of the situatioin, you also have the facts right about problems and limitations with that implementation.

OK, so given that - I think your best answer is to use the REST API directly from java. That link provides detailed documentation. But essentially, you won't be dealing with Node and Relationship objects, but rather you'll be working with HTTP requests and responses, and JSON processing.

See the examples behind the link I provided, it provides lots of code examples for how to get this to work. The good news is that you can do anything on the server side. The bad news is that it's way less convenient. I'm hoping too for a really good GraphDatabaseService implementation in the future. It would be very powerful if my code didn't have to care whether the DB was a local file, or a remote service.

like image 100
FrobberOfBits Avatar answered Oct 06 '22 23:10

FrobberOfBits