spring-bootspring-data-neo4jtestcontainersagens-graph

How to use AgensGraph as a Neo4j replacement with Spring Boot?


Given a Spring-Boot application using Neo4j, I'd like to replace Neo4j with AgensGraph. But so far, while trying in the integration tests, I did not yet succeed.

My test initialization code looks as follows

@ExtendWith(SpringExtension::class)
@ActiveProfiles("test")
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
@Testcontainers
class FullStackTest {
    companion object {
        @Container
        val agensgraph = GenericContainer(
            "bitnine/agensgraph:v2.1.3"
        ).withExposedPorts(
            5432
        ).withEnv(
            "POSTGRES_PASSWORD", "agensgraph"
        )

        @BeforeAll
        @JvmStatic
        @Suppress("unused")
        fun neo4jProperties() {
            agensgraph.start()
            val uri = String.format("bolt://" + agensgraph.host + ":" + agensgraph.getMappedPort(5432))
            System.setProperty("spring.neo4j.uri", uri)
            System.setProperty("spring.neo4j.authentication.username", "postgres")
            System.setProperty("spring.neo4j.authentication.password", "agensgraph")
        }
    }


    // ... tests ...
}

Running it results in the following error:

org.neo4j.driver.exceptions.ServiceUnavailableException: Connection to the database terminated. Please ensure that your database is listening on the correct host and port and that you have compatible encryption settings both on Neo4j server and driver. Note that the default encryption setting has changed in Neo4j 4.0.

Am I doing something wrong or is it just not compatible?


Solution

  • Unfortunately, AgensGraph doesn't support Bolt protocol that is used by Neo4J. Being a PostgreSQL extension it requires using PostgreSQL protocol.

    After starting an AgensGraph instance with:

    docker run -p 5432:5432 -e POSTGRES_HOST_AUTH_METHOD=trust -it --rm bitnine/agensgraph:latest
    

    I can connect to it using psql -h localhost -p 5432 -U postgres, but when I try cypher-shell -a neo4j://localhost:5432 it fails and I get this in AgensGraph output:

    2024-04-23 08:22:41.826 UTC [58] LOG:  invalid length of startup packet