using remote shell combined with Neo4j embedded

Neo4j can be deployed in multiple ways. Either you can run it as a server in a separate process, just like a classic database, or you can use embedded mode where your application controls the lifecycle of the graph database. Both, embedded and server mode can be used to setup a HA scenario with Neo4j enterprise edition.

In cases where Neo4j is used in embedded mode, there is often a demand for having a maintenance channel to the database, e.g. for fixing wrong data. Nothing simpler than that, there’s an easy way to enable the remote shell together with embedded mode, see a example written in groovy:

@Grab(group="org.neo4j", module="neo4j-kernel", version="2.0.0")
@Grab(group="org.neo4j", module="neo4j-lucene-index", version="2.0.0")
@Grab(group='org.neo4j', module='neo4j-shell', version='2.0.0')

import org.neo4j.graphdb.factory.GraphDatabaseFactory
def db = new GraphDatabaseFactory().newEmbeddedDatabaseBuilder("/tmp/graph.db")

println """starting embedded graph db
use bin/neo4j-shell from a new distribution to connect
we're keeping the graphdb open for 120 secs"""

sleep 120 * 1000
println "shutting down embedded graph db now"

The trick is to

  1. have the neo4j-shell-<version>.jar on your classpath and
  2. pass in the config option remote_shell_enabled='true'

With this in place you can use the bin/neo4j-shell from your Neo4j distribution and access your embedded instance.


Leave a Reply

Your email address will not be published. Required fields are marked *