Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Howto Use Neo4j From Erlang

nerlo edited this page · 13 revisions

Starting And Stopping

To use neo4j from within Erlang using the neo4j bridge you first have to ensure that the ej application is running. This application starts, stops and maintains the Java node containing all of the graph database functionality. You start ej like this, supposed everything is properly added to your code path.

ej_app:start().

Next you have to start the neo4j application. This application ensures the availability of the database in the Java node. If the node crashes and has been restarted by ej, this application restarts the database so that this should be almost always available if both applications are working.

neo4j_app:start().

You can always check if the database is available:

neo4j:has_db().

To stop everything in a controlled way, you go the other way around.

neo4j_app:stop().
ej_app:stop().

Dealing With Graphs

If you start with an empty database you first have to create some vertices. Currently, a neo4j instance is always bound to one single database so you do not have to select a certain database. All operations will be executed at the configured instance.

V1 = neo4j:add_vertex().
V2 = neo4j:add_vertex().

You can add properties to each vertex.

neo4j:vertex_set_property(V1, name, alice).
neo4j:vertex_set_property(V2, name, bob).

Next you connect the two vertices with an edge.

E1 = neo4j:add_edge(V1, V2).

Configuration

Probably the most important configuration option is to tell the system where to find the database. This is done in the properties file in the bin directory and evaluated by the Java node on startup.

graphdb.db.path=../db

If no database exists at the specified location an empty database it is automatically created. This is a feature of Neo4j. One may discuss if we should overwrite this feature to not use an empty database by accident.

The logging of the Java node is also configured in the properties file. For more information consult the log4j documentation.

Another very important Java configuration is the message handler property:

ej.msgHandler=org.ister.nerlo.EjMsgHandler

This tells the ej application to use the nerlo message handler to handle incoming Erlang messages.

Logging

At the moment all Erlang logging goes to stdout while Java uses log4j which can be configured in the properties file. Soon we will integrate log4erl to have the same comfort in Erlang as in Java.

Something went wrong with that request. Please try again.