Showing results forΒ 
Search instead forΒ 
Did you mean:Β 

Specify read/write transaction before query execution in spring data neo4j

Node Clone

I am using org.springframework.boot:spring-boot-starter-data-neo4j to connect with graph db.

I am looking for a way to specify read/write for a transaction so that write queries are routes to leader instance and reads are for other instances. This helps to reduce load on leader instance which in turn improve database performance.

How can we specify in code?

Here is my transaction manager with driver instantiation

    class Neo4jConfig(
        val neo4jDBUri: String,

        val neo4jDbUserName: String,

        val neo4jDbUserPassword: String
    ) : AbstractNeo4jConfig() {

        override fun driver(): Driver {
            val config: Config = Config.builder()
                .withMaxTransactionRetryTime(60, TimeUnit.SECONDS)
                .withRoutingTablePurgeDelay(1, TimeUnit.SECONDS)
                .withConnectionAcquisitionTimeout(2 * 60, TimeUnit.SECONDS)
                .withConnectionLivenessCheckTimeout(2 * 60, TimeUnit.SECONDS)
                .withMaxConnectionLifetime(5, TimeUnit.MINUTES)

            return GraphDatabase
                .driver(neo4jDBUri, AuthTokens.basic(neo4jDbUserName, neo4jDbUserPassword), config)

    // Refer:
    fun reactiveTransactionManager(
        driver: Driver,
        databaseNameProvider: ReactiveDatabaseSelectionProvider
    😞 ReactiveTransactionManager = ReactiveNeo4jTransactionManager(driver, databaseNameProvider)

    // Refer:
    @Configuration(proxyBeanMethods = false)
    internal class DataConfig {
        fun reactiveAuditorAware(): ReactiveAuditorAware<String> = ReactiveAuditorAware { Mono.just("Audit enabled") }

query part is like this:

class CloudFilesDao(val client: ReactiveNeo4jClient) {
suspend fun addEvent(){
val query = "merge ****"