Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
10-01-2019 02:37 AM
Hello neo4j folks,
I have bundled an embedded neo4j database in my OSGi server and ran successfully the database with cypher query module but still failed at using the bolt connector.
My OSGi setting is as follow :
I embedd neo4j in an api bundle and instanciate an embedded database in another bundle.
My neo4j api bundle descriptor is : pom.xml
My Code in the other bundle is :
..
GraphDatabaseFactory gdbf = new GraphDatabaseFactory();
BoltConnector bolt = new BoltConnector("0");
this.db = gdbf.setUserLogProvider( new Slf4jLogProvider() )
.newEmbeddedDatabaseBuilder(db_path)
.setConfig( bolt.type, "BOLT" )
.setConfig( bolt.enabled, Settings.TRUE)
.setConfig( bolt.address, "0.0.0.0:7688" )
.setConfig(bolt.encryption_level, BoltConnector.EncryptionLevel.OPTIONAL.toString())
.setConfig(ShellSettings.remote_shell_enabled, Settings.TRUE)
.newGraphDatabase();
this.register_shutdown_hook();
final StringBuilder sb = new StringBuilder();
sb.append("CREATE\n");
sb.append("(ben {name: 'Ben'}),\n");
sb.append("(arnold {name: 'Arnold'}),\n");
sb.append("(charlie {name: 'Charlie'}),\n");
sb.append("(gordon {name: 'Gordon'}),\n");
sb.append("(lucy {name: 'Lucy'}),\n");
sb.append("(emily {name: 'Emily'}),\n");
sb.append("(sarah {name: 'Sarah'}),\n");
sb.append("(kate {name: 'Kate'}),\n");
sb.append("(mike {name: 'Mike'}),\n");
sb.append("(paula {name: 'Paula'}),\n");
sb.append("(ben)-[:FRIEND]->(charlie),\n");
sb.append("(charlie)-[:FRIEND]->(lucy),\n");
sb.append("(lucy)-[:FRIEND]->(sarah),\n");
sb.append("(sarah)-[:FRIEND]->(mike),\n");
sb.append("(arnold)-[:FRIEND]->(gordon),\n");
sb.append("(gordon)-[:FRIEND]->(emily),\n");
sb.append("(emily)-[:FRIEND]->(kate),\n");
sb.append("(kate)-[:FRIEND]->(paula)");
logger.trace("Creating database..");
this.db.execute(sb.toString());
logger.trace("Querying database..");
try ( Transaction tx = this.db.beginTx() ) {
for( Node node : this.db.getAllNodes() ) {
for( Relationship rel : node.getRelationships() ) {
logger.trace("{} -[:{}]-> {}", rel.getStartNode().getProperty("name"), rel.getType(), rel.getEndNode().getProperty("name"));
}
}
tx.success();
}
..
I use a vanilla neo4j database distribution to connect to my external bolt server at 7688
$ ./neo4j console
...
2019-09-27 14:05:48.790+0000 INFO Bolt enabled on 0.0.0.0:7687.
2019-09-27 14:05:50.522+0000 INFO Started.
I start my OSGi server and check that my port 7688 is listening :
$ netstat -plten | grep java
tcp6 0 0 :::7687 :::* LISTEN 1000 854839 13519/java
tcp6 0 0 :::7688 :::* LISTEN 1000 935543 16817/java
I open the neo4j front end at http://localhost:7474/browser/ and try to connect to my embedded instance from URL bolt://localhost:7688
Unfortunately I have the following error from the browser :
Firefox can’t establish a connection to the server at ws://localhost:7688/.
I have tried my embedded code snippet in a java project without OSGi and the bolt connector works well.
To illustrate the problem I have made a simple test with telnet.
With a working node the following command :
$ telnet localhost 7688
Trying ::1...
Connected to localhost.
Escape character is '^]'.
The connection holds and one has to strike CTRL+C to finish the connection.
But with my node I have :
$ telnet localhost 7688
Trying ::1...
Connected to localhost.
Escape character is '^]'.
Connection closed by foreign host.
As soon as the connection is established the server close the connection.
I don't have any error message nor any clue that can lead me to the solution.
Any ideas ??
thanks
Cyrille
All the sessions of the conference are now available online