提交 92288630 编写于 作者: S Sebastien Deleuze

Document Reactive APIs support

上级 54192cf5
......@@ -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<Account>` -- streaming scenario, possibly SSE depending on the requested content type.
* `Observable<Account>` -- same but using RxJava `Observable` type.
* `Flowable<Account>` -- same but using RxJava 2 `Flowable` type.
* `Publisher<Account>` or `Flow.Publisher<Account>` -- any type implementing Reactive Streams `Publisher` is supported.
* `Flux<ServerSentEvent>` -- SSE streaming.
* `Mono<Void>` -- 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<User>` will be serialized by
and flushed. For example a REST endpoint that returns a `Flux<Account>` will be serialized by
default as following:
* `application/json`: a `Flux<User>` is handled as an asynchronous collection and
* `application/json`: a `Flux<Account>` 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<User>` will be handled as a stream of `User` elements
* `application/stream+json`: a `Flux<Account>` 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<User>` or `Flux<ServerSentEvent<User>>` will be handled as
a stream of `User` or `ServerSentEvent` elements serialized as individual SSE elements
* `text/event-stream`: a `Flux<Account>` or `Flux<ServerSentEvent<Account>>` 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.
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册