Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Access Neo4j in server mode with EmbeddedGraphDatabase?

Tags:

neo4j

If I run neo4j in server mode so it is accessible using the REST API, can I access the same neo4j instance with EmbeddedGraphDatabase-class?

I am thinking of a production setup where a Java-app using EmbeddedGraphDatabase is driving the logic, but other clients might navigate the data with REST in readonly mode.

like image 965
Daniel Avatar asked May 07 '11 13:05

Daniel


1 Answers

What you are describing is a server plugin or extension. That way you expose your database via the REST API but at the same time you can access the embedded graph db hihgly performant from your custom plugin/extension code.

In your custom code you can get a GraphDatabaseService injected on which you operate.

You deploy your custom extensions as jars with your neo4j-server and have client code operate over a domain oriented restful API with it.

// extension sample
@Path( "/helloworld" )
public class HelloWorldResource {

private final GraphDatabaseService database;

public HelloWorldResource( @Context GraphDatabaseService database) {
  this.database = database;
}

@GET
@Produces( MediaType.TEXT_PLAIN )
@Path( "/{nodeId}" )
public Response hello( @PathParam( "nodeId" ) long nodeId ) {
    // Do stuff with the database
    return Response.status( Status.OK ).entity(
            ( "Hello World, nodeId=" + nodeId).getBytes() ).build();
}
}

Docs for writing plugins and extensions.

like image 50
Michael Hunger Avatar answered Jan 07 '23 21:01

Michael Hunger