Reactive Infrastructure

响应式 Cassandra 支持包含广泛的功能:

The reactive Cassandra support contains a wide range of features:

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

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

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

  • Exception translation into Spring’s portable Data Access Exception Hierarchy.

  • Feature rich object mapping integrated with Spring’s Conversion Service.

  • Java-based Query, Criteria, and Update DSLs.

  • Automatic implementation of Repository interfaces, including support for custom finder methods.

对于大多数面向数据的任务,可以使用 ReactiveCassandraTemplate 或存储库支持,它们使用丰富的对象映射功能。ReactiveCqlTemplate 通常用于递增计数器或执行即席 CRUD 操作。ReactiveCqlTemplate 还提供回调方法,可以轻松获得低级 API 对象,例如 com.datastax.oss.driver.api.core.CqlSession,这让你可以直接与 Cassandra 通信。用于 Apache Cassandra 的 Spring Data 在各种 API 的对象上使用与 DataStax Java 驱动程序中找到的一致的命名约定,以便立即识别它们,以便你可以将现有知识映射到 Spring API。

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.

响应式使用分为两个阶段:组成和执行。

Reactive usage is broken up into two phases: Composition and Execution.

调用存储库方法可让你通过获取 `Publisher`实例并应用运算符来组成反应序列。在订阅之前不会发生任何 I/O。将反应序列传递给反应执行基础设施,例如 Spring WebFluxVert.x),订阅发布者并启动实际执行。有关详细信息,请参阅 the Project reactor documentation

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.

Reactive Composition Libraries

反应式空间提供各种反应式组合函数库。最常见的函数库为 RxJavaProject Reactor

The reactive space offers various reactive composition libraries. The most common libraries are RxJava and Project Reactor.

适用于 Apache Cassandra 的 Spring Data 构建于 DataStax Cassandra Driver之上。该驱动程序不是反应式的,但其异步功能允许我们采用并公开 Publisher API,通过依赖 Reactive Streams 计划为最大化可交互性提供支持。通过使用 Project Reactor 的 FluxMono 类型提供诸如 ReactiveCassandraOperations 的静态 API。Project Reactor 提供各种适配器,用于转换反应式包装器类型(FluxObservable 并返回),但是转换很容易使代码变得混乱。

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.