Reactive Cassandra

Explore nonblocking and responsive database interactions through reactive programming with Spring Data Cassandra.

Reactive programming in Spring Data Cassandra brings asynchronous and nonblocking capabilities, enabling efficient data handling. It empowers applications with responsiveness, scalability, and seamless interaction with Cassandra databases, catering to modern, high-performance requirements.

Quick setup

First, we should add the spring-boot-starter-data-cassandra-reactive Spring Boot starter data dependency to the build.gradle file to enable the reactive programming support of Spring Data Cassandra.

Press + to interact
plugins {
id 'java'
id 'org.springframework.boot' version '2.7.5'
id 'io.spring.dependency-management' version '1.1.0'
}
group = 'com.smartdiscover'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '11'
repositories {
mavenCentral()
}
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-data-cassandra'
implementation 'org.springframework.boot:spring-boot-starter-data-cassandra-reactive'
implementation 'org.projectlombok:lombok:1.18.26'
annotationProcessor 'org.projectlombok:lombok'
}

Reactive Cassandra repository

The ReactiveCassandraRepository interface is provided by Spring Data Cassandra for reactive programming, extending the ReactiveCrudRepository interface.

Press + to interact
package org.springframework.data.cassandra.repository;
public interface ReactiveCassandraRepository<T, ID> extends ReactiveCrudRepository<T, ID> {
<S extends T> Mono<S> insert(S entity);
<S extends T> Flux<S> insert(Iterable<S> entities);
<S extends T> Flux<S> insert(Publisher<S> entities);
@Override
Flux<T> findAllById(Iterable<ID> iterable);
@Override
Flux<T> findAllById(Publisher<ID> publisher);
}

Code ...