|
4 | 4 | `spring-webflux` depends on `reactor-core` and uses it internally to compose asynchronous
|
5 | 5 | logic and to provide Reactive Streams support. Generally, WebFlux APIs return `Flux` or
|
6 | 6 | `Mono` (since those are used internally) and leniently accept any Reactive Streams
|
7 |
| -`Publisher` implementation as input. The use of `Flux` versus `Mono` is important, because |
8 |
| -it helps to express cardinality -- for example, whether a single or multiple asynchronous |
9 |
| -values are expected, and that can be essential for making decisions (for example, when |
10 |
| -encoding or decoding HTTP messages). |
| 7 | +`Publisher` implementation as input. |
| 8 | +When a `Publisher` is provided, it can be treated only as a stream with unknown semantics (0..N). |
| 9 | +If, however, the semantics are known, you should wrap it with `Flux` or `Mono.from(Publisher)` instead |
| 10 | +of passing the raw `Publisher`. |
| 11 | +The use of `Flux` versus `Mono` is important, because it helps to express cardinality -- |
| 12 | +for example, whether a single or multiple asynchronous values are expected, |
| 13 | +and that can be essential for making decisions (for example, when encoding or decoding HTTP messages). |
11 | 14 |
|
12 | 15 | For annotated controllers, WebFlux transparently adapts to the reactive library chosen by
|
13 | 16 | the application. This is done with the help of the
|
14 | 17 | {spring-framework-api}/core/ReactiveAdapterRegistry.html[`ReactiveAdapterRegistry`], which
|
15 | 18 | provides pluggable support for reactive library and other asynchronous types. The registry
|
16 | 19 | has built-in support for RxJava 3, Kotlin coroutines and SmallRye Mutiny, but you can
|
17 | 20 | register others, too.
|
18 |
| - |
19 |
| -For functional APIs (such as <<webflux-fn>>, the `WebClient`, and others), the general rules |
20 |
| -for WebFlux APIs apply -- `Flux` and `Mono` as return values and a Reactive Streams |
21 |
| -`Publisher` as input. When a `Publisher`, whether custom or from another reactive library, |
22 |
| -is provided, it can be treated only as a stream with unknown semantics (0..N). If, however, |
23 |
| -the semantics are known, you can wrap it with `Flux` or `Mono.from(Publisher)` instead |
24 |
| -of passing the raw `Publisher`. |
25 |
| - |
26 |
| -For example, given a `Publisher` that is not a `Mono`, the Jackson JSON message writer |
27 |
| -expects multiple values. If the media type implies an infinite stream (for example, |
28 |
| -`application/json+stream`), values are written and flushed individually. Otherwise, |
29 |
| -values are buffered into a list and rendered as a JSON array. |
0 commit comments