When running a Neo4J database server standalone (on Ubuntu 14.04), configuration options are set for the global installation in etc/neo4j/neo4j.conf
or possibly $NEO4J_HOME/conf/neo4j.conf
.
However, when instantiating a Neo4j database from Java or Scala using Apache's Neo4jGraph
class (org.apache.tinkerpop.gremlin.neo4j.structure.Neo4jGraph
), there is no global installation, and the constructor does not (as far as I can tell) look for any configuration files.
In particular, when running the test suite for my application, I end up with many simultaneous instances of Neo4jGraph
, which ends up throwing a java.net.BindException: Address already in use
because all of these instances are trying to communicate over a small range of ports for online backup, which I don't actually need. These channels are set with config options dbms.backup.address
(default value: 127.0.0.1:6362-6372
) and dbms.backup.enabled
(default value: true
).
My problem would be solved by setting dbms.backup.enabled
to false
, or expanding the port range.
Things that have not worked:
Creating /etc/neo4j/neo4j.conf
containing the line dbms.backup.enabled=false
.
Creating the same file in my project's src/main/resources
directory.
Creating the same file in src/main/resources/neo4j
.
Manually setting the configuration property inside the Scala code:
val db = new Neo4jGraph(dataDirectory)
db.configuration.addProperty("dbms.backup.enabled",false)
db.configuration.addProperty("neo4j.conf.dbms.backup.enabled",false)
db.configuration.addProperty("gremlin.neo4j.conf.dbms.backup.enabled",false)
How should I go about setting this property?
Manipulating db.configuration
after the database connection had already been opened was definitely futile.
stephen mallette's answer was on the right track, but this particular configuration doesn't appear to pass through in the way his linked example does. There is a naming mismatch between the configuration keys expected in neo4j.conf
and those expected in org.neo4j.backup.OnlineBackupKernelExtension
. Instead of dbms.backup.address
and dbms.backup.enabled
, that class looks for config keys online_backup_server
and online_backup_enabled
.
I was not able to get these keys passed down to the underlying Neo4jGraphAPI
instance correctly. What I had to do, instead, was the following:
import org.neo4j.tinkerpop.api.impl.Neo4jFactoryImpl
import scala.collection.JavaConverters._
val factory = new Neo4jFactoryImpl()
val config = Map(
"online_backup_enabled" -> "true",
"online_backup_server" -> "0.0.0.0:6350-6359"
).asJava
val db = Neo4jGraph.open(factory.newGraphDatabase(dataDirectory,config))
With this initialization, the instance correctly listened for backups on port 6350; changing "true"
to "false"
disabled backup listening.