Micronaut Neo4j

Integration between Micronaut and Neo4j

Version: 1.1.0

1 Introduction

This project includes integration between Micronaut and Neo4j.

Release History

1.1.0

  • Upgrade to Neo4j Java Driver 1.7.2

2 Setting up the Neo4j Bolt Driver

Using the CLI

If you are creating your project using the Micronaut CLI, supply the neo4j-bolt feature to configure the Neo4j Bolt driver in your project:

$ mn create-app my-app --features neo4j-bolt

To configure the Neo4j Bolt driver you should first add the neo4j-bolt module to your classpath:

compile 'io.micronaut.configuration:micronaut-:micronaut-neo4j-bolt'
<dependency>
    <groupId>io.micronaut.configuration</groupId>
    <artifactId>micronaut-:micronaut-neo4j-bolt</artifactId>
</dependency>

You should then configure the URI of the Neo4j server you wish to communicate with in application.yml:

Configuring neo4j.uri
neo4j:
    uri: bolt://localhost
The neo4j.uri setting should be in the format as described in the Connection URIs section of the Neo4j documentation

Once you have the above configuration in place you can inject an instance of the org.neo4j.driver.v1.Driver bean, which features both a synchronous blocking API and a non-blocking API based on CompletableFuture.

Neo4j Health Checks

When the micronaut-neo4j-bolt module is activated a Neo4jHealthIndicator is activated resulting in the /health endpoint and CurrentHealthStatus interface resolving the health of the Neo4j connection.

See the section on the Health Endpoint for more information.

3 Configuring the Neo4j Bolt Driver

The configuration can be further customized with all the options available using the Neo4jBoltConfiguration class.

The Neo4jBoltConfiguration also exposes all the options for the org.neo4j.driver.v1.Config.ConfigBuilder class.

Below represents an example configuration:

Customizing the Bolt Configuration
neo4j:
    uri: bolt://localhost
    maxConnectionPoolSize: 50
    connectionAcquisitionTimeout: 30s
You can also create a BeanCreatedEventListener bean and listen for the creation of the Neo4jBoltConfiguration to further programmatically customize configuration

4 Neo4j and Testing

You can embed Neo4j for testing by including a dependency on the Neo4j test harness:

test 'org.neo4j.test:neo4j-harness'
<dependency>
    <groupId>org.neo4j.test</groupId>
    <artifactId>neo4j-harness</artifactId>
    <scope>test</scope>
</dependency>

If the Neo4j server is not already running on the configured port an embedded version will be started.

You can configure the options for the embedded Neo4j server using the neo4j.embedded settings exposed by Neo4jBoltConfiguration.

One useful option is ephemeral which ensures the data is cleaned up between test runs. For example in application-test.yml:

Using ephemeral
neo4j:
    embedded:
        ephemeral: true