2023-04-20 22:51:32 +08:00
|
|
|
[[webflux-reactive-libraries]]
|
|
|
|
= Reactive Libraries
|
|
|
|
|
|
|
|
`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
|
2024-05-13 19:12:53 +08:00
|
|
|
`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).
|
2023-04-20 22:51:32 +08:00
|
|
|
|
|
|
|
For annotated controllers, WebFlux transparently adapts to the reactive library chosen by
|
|
|
|
the application. This is done with the help of the
|
2023-11-21 22:59:24 +08:00
|
|
|
{spring-framework-api}/core/ReactiveAdapterRegistry.html[`ReactiveAdapterRegistry`], which
|
2023-04-20 22:51:32 +08:00
|
|
|
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.
|