diff --git a/src/asciidoc/web-flux.adoc b/src/asciidoc/web-flux.adoc index fbe1cd1df03..f6979de255e 100644 --- a/src/asciidoc/web-flux.adoc +++ b/src/asciidoc/web-flux.adoc @@ -171,6 +171,12 @@ that enable the serialization of a `Flux` of bytes to and from typed objects. The `spring-web` module adds JSON (Jackson) and XML (JAXB) implementations for use in web applications as well as others for SSE streaming and zero-copy file transfer. +The following Reactive APIs are supported: + +* Reactor 3.x is supported out of the box +* RxJava 2.x is supported when `io.reactivex.rxjava2:rxjava` dependency is on the classpath +* RxJava 1.x is supported when both `io.reactivex:rxjava` and `io.reactivex:rxjava-reactive-streams` (https://github.com/ReactiveX/RxJavaReactiveStreams[adapter between RxJava and Reactive Streams]) dependencies are on the classpath + For example the request body can be one of the following way and it will be decoded automatically in both the annotation and the functional programming models: @@ -187,6 +193,7 @@ The response body can be one of the following: * `Flux` -- streaming scenario, possibly SSE depending on the requested content type. * `Observable` -- same but using RxJava `Observable` type. * `Flowable` -- same but using RxJava 2 `Flowable` type. +* `Publisher` or `Flow.Publisher` -- any type implementing Reactive Streams `Publisher` is supported. * `Flux` -- SSE streaming. * `Mono` -- request handling completes when the `Mono` completes. * `Account` -- serialize without blocking the given Account; implies a synchronous, non-blocking controller method. @@ -195,17 +202,17 @@ when the method returns; implies a synchronous, non-blocking controller method. When using stream types like `Flux` or `Observable`, the media type specified in the request/response or at mapping/routing level is used to determine how the data should be serialized -and flushed. For example a REST endpoint that returns a `Flux` will be serialized by +and flushed. For example a REST endpoint that returns a `Flux` will be serialized by default as following: -* `application/json`: a `Flux` is handled as an asynchronous collection and +* `application/json`: a `Flux` is handled as an asynchronous collection and serialized as a JSON array with an explicit flush when the `complete` event is emitted. -* `application/stream+json`: a `Flux` will be handled as a stream of `User` elements +* `application/stream+json`: a `Flux` will be handled as a stream of `Account` elements serialized as individual JSON object separated by new lines and explicitly flushed after each element. The `WebClient` supports JSON stream decoding so this is a good use case for server to server use case. -* `text/event-stream`: a `Flux` or `Flux>` will be handled as - a stream of `User` or `ServerSentEvent` elements serialized as individual SSE elements +* `text/event-stream`: a `Flux` or `Flux>` will be handled as + a stream of `Account` or `ServerSentEvent` elements serialized as individual SSE elements using by default JSON for data encoding and explicit flush after each element. This is well suited for exposing a stream to browser clients. `WebClient` supports reading SSE streams as well.