Over a million developers have joined DZone.

Using Remote Shell Combined with Neo4j Embedded

· Java Zone

Check out this 8-step guide to see how you can increase your productivity by skipping slow application redeploys and by implementing application profiling, as you code! Brought to you in partnership with ZeroTurnaround.

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 an 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")
  .setConfig(remote_shell_enabled:'true')
  .newGraphDatabase()

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"
db.shutdown()

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.

The Java Zone is brought to you in partnership with ZeroTurnaround. Check out this 8-step guide to see how you can increase your productivity by skipping slow application redeploys and by implementing application profiling, as you code!

Topics:

Published at DZone with permission of Stefan Armbruster, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

The best of DZone straight to your inbox.

SEE AN EXAMPLE
Please provide a valid email address.

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.
Subscribe

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}