Reactive Libraries
spring-webflux
依赖于 reactor-core
,并在内部将其用于组合异步逻辑并提供 Reactive Streams 支持。通常,WebFlux API 会返回 Flux
或 Mono
(因为它们在内部使用)并宽松地接受任何 Reactive Streams Publisher
实现作为输入。提供 Publisher
时,它只能被视为语义未知(0..N)的流。但是,如果语义已知,则应使用 Flux
或 Mono.from(Publisher)
来包装它,而不是传递原始 Publisher
。使用 Flux
与 Mono
很重要,因为它有助于表示基数(例如,期望单个还是多个异步值),并且对于决策(例如,编码或解码 HTTP 消息时)至关重要。
spring-webflux
depends on reactor-core
and uses it internally to compose asynchronous
logic and to provide Reactive Streams support. Generally, WebFlux APIs return Flux
or
Mono
(since those are used internally) and leniently accept any Reactive Streams
Publisher
implementation as input.
When a Publisher
is provided, it can be treated only as a stream with unknown semantics (0..N).
If, however, the semantics are known, you should wrap it with Flux
or Mono.from(Publisher)
instead
of passing the raw Publisher
.
The use of Flux
versus Mono
is important, because it helps to express cardinality — for example, whether a single or multiple asynchronous values are expected,
and that can be essential for making decisions (for example, when encoding or decoding HTTP messages).
对于带有注释的控制器,WebFlux 可以自动适应应用程序选择的反应式库。这是在`https://docs.spring.io/spring-framework/docs/current/javadoc-api/org/springframework/core/ReactiveAdapterRegistry.html[ReactiveAdapterRegistry
]` 的帮助下完成的,它为反应式库和其他异步类型提供了可插拔式支持。注册表已内置对 RxJava 3、Kotlin 协程和小麦穗兵变的支持,但你也可以注册其他内容。
For annotated controllers, WebFlux transparently adapts to the reactive library chosen by
the application. This is done with the help of the
ReactiveAdapterRegistry
, which
provides pluggable support for reactive library and other asynchronous types. The registry
has built-in support for RxJava 3, Kotlin coroutines and SmallRye Mutiny, but you can
register others, too.