开发者

Access Neo4j in server mode with EmbeddedGraphDatabase?

开发者 https://www.devze.com 2023-03-04 18:44 出处:网络
If I run neo4j in server mode so it is accessible us开发者_Go百科ing the REST API, can I access the same neo4j instance with EmbeddedGraphDatabase-class?

If I run neo4j in server mode so it is accessible us开发者_Go百科ing 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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消