Daniel
Daniel

Reputation: 744

Access Neo4j in server mode with EmbeddedGraphDatabase?

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.

Upvotes: 7

Views: 2594

Answers (1)

Michael Hunger
Michael Hunger

Reputation: 41676

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.

Upvotes: 7

Related Questions