Access Neo4j in server mode with EmbeddedGraphDatabase?

前端 未结 1 963
臣服心动
臣服心动 2021-02-04 17:37

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 productio

1条回答
  •  醉梦人生
    2021-02-04 18:13

    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 讨论(0)
提交回复
热议问题