Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

Using Remote Shell Combined with Neo4j Embedded

DZone's Guide to

Using Remote Shell Combined with Neo4j Embedded

· Java Zone
Free Resource

Just released, a free O’Reilly book on Reactive Microsystems: The Evolution of Microservices at Scale. Brought to you in partnership with Lightbend.

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.

Strategies and techniques for building scalable and resilient microservices to refactor a monolithic application step-by-step, a free O'Reilly book. Brought to you in partnership with Lightbend.

Topics:

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

Opinions expressed by DZone contributors are their own.

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

{{ parent.tldr }}

{{ parent.urlSource.name }}