For the latest stable version, please use Spring Data Cassandra 4.4.0!spring-doc.cn

Reactive Infrastructure

The reactive Cassandra support contains a wide range of features:spring-doc.cn

  • Spring configuration support using Java-based @Configuration classes.spring-doc.cn

  • ReactiveCqlTemplate helper class that increases productivity by properly handling common Cassandra data access operations.spring-doc.cn

  • ReactiveCassandraTemplate helper class that increases productivity by using ReactiveCassandraOperations in a reactive manner. It includes integrated object mapping between tables and POJOs.spring-doc.cn

  • Exception translation into Spring’s portable Data Access Exception Hierarchy.spring-doc.cn

  • Feature rich object mapping integrated with Spring’s Conversion Service.spring-doc.cn

  • Java-based Query, Criteria, and Update DSLs.spring-doc.cn

  • Automatic implementation of Repository interfaces, including support for custom finder methods.spring-doc.cn

For most data-oriented tasks, you can use the ReactiveCassandraTemplate or the repository support, which use the rich object mapping functionality. ReactiveCqlTemplate is commonly used to increment counters or perform ad-hoc CRUD operations. ReactiveCqlTemplate also provides callback methods that make it easy to get low-level API objects, such as com.datastax.oss.driver.api.core.CqlSession, which let you communicate directly with Cassandra. Spring Data for Apache Cassandra uses consistent naming conventions on objects in various APIs to those found in the DataStax Java Driver so that they are immediately familiar and so that you can map your existing knowledge onto the Spring APIs.spring-doc.cn

Reactive usage is broken up into two phases: Composition and Execution.spring-doc.cn

Calling repository methods lets you compose a reactive sequence by obtaining Publisher instances and applying operators. No I/O happens until you subscribe. Passing the reactive sequence to a reactive execution infrastructure, such as Spring WebFlux or Vert.x), subscribes to the publisher and initiate the actual execution. See the Project reactor documentation for more detail.spring-doc.cn

Reactive Composition Libraries

The reactive space offers various reactive composition libraries. The most common libraries are RxJava and Project Reactor.spring-doc.cn

Spring Data for Apache Cassandra is built on top of the DataStax Cassandra Driver. The driver is not reactive but the asynchronous capabilities allow us to adopt and expose the Publisher APIs to provide maximum interoperability by relying on the Reactive Streams initiative. Static APIs, such as ReactiveCassandraOperations, are provided by using Project Reactor’s Flux and Mono types. Project Reactor offers various adapters to convert reactive wrapper types (Flux to Observable and back), but conversion can easily clutter your code.spring-doc.cn