@ -12,17 +12,16 @@ This section provides basic information on the Spring Web Reactive support in Sp
@@ -12,17 +12,16 @@ This section provides basic information on the Spring Web Reactive support in Sp
In plain terms reactive programming is about non-blocking applications that are asynchronous
and event-driven and require a small number of threads to scale. A key aspect of that
definition is the concept of backpressure which is a mechanism to ensures producers
definition is the concept of backpressure which is a mechanism to ensure producers
don't overwhelm consumers. For example in a pipeline of reactive components that extends
from the database to the HTTP server when an HTTP connection slows down the data
repository slows down as well or stops until capacity frees up.
from the database to the HTTP socket when the HTTP client is slow the data
repository slows down or stops until capacity frees up.
Reactive programming involves a shift from imperative to declarative, async composition
of logic. This is comparable to how `CompletableFuture` in Java 8 allows declaring
follow-up actions in lambda expressions to be executed when the future completes.
From a programming model perspective reactive programming involves a major shift from imperative style logic
to a declarative composition of async logic. It is comparable to using `CompletableFuture` in Java 8
and composing follow-up actions via lambda expressions.
A proper introduction to Reactive programming is beyond scope of this documentation.
For a more extended introduction check the excellent multi-part series
For a more extended introduction to reactive programming check the excellent multi-part series
https://spring.io/blog/2016/06/07/notes-on-reactive-programming-part-i-the-reactive-landscape["Notes on Reactive Programming"]
by Dave Syer.
@ -33,23 +32,23 @@ by Dave Syer.
@@ -33,23 +32,23 @@ by Dave Syer.
* `Observable<Account> accounts` -- input streaming with RxJava.
The above also applies to return value handling:
* `Mono<Account>` -- serialize without blocking the given Account when the `Mono` completes.
* `Singe<Account>` -- same but using RxJava.
* `Flux<Account>` -- streaming scenario, possibly SSE depending on the requested content type.
* `Flux<SseEvent>` -- SSE streaming.
* `Observable<SseEvent>` -- same but using RxJava.
* `Mono<Void>` -- request handling completes when the `Mono` completes.
* `void` -- request handling completes when the method returns;
implies a synchronous, non-blocking controller method.
* `Account` -- serialize without blocking the given Account;
implies a synchronous, non-blocking controller method.
[[web-reactive-client]]
@ -103,13 +113,13 @@ The same principle also applies on the side of return value handling.
@@ -103,13 +113,13 @@ The same principle also applies on the side of return value handling.
Spring Framework 5 adds a new reactive `WebClient` in addition to the existing `RestTemplate`.
Much like on the server side each supported HTTP client is adapted to a set of shared,
Each supported HTTP client (e.g. Reactor Netty) is adapted to a set of shared,
reactive `ClientHttpRequest` and `ClientHttpResponse` abstractions that expose the request
and response body as `Flux<DataBuffer>` with full backpressure support on the read and
the write side. The `Encoder` and `Decoder` abstractions from `spring-core` also used on
the client side for serialization of a `Flux` of bytes to and from typed objects.
the write side. The `Encoder` and `Decoder` abstractions from `spring-core` are also used on
the client side for the serialization of a `Flux` of bytes to and from typed objects.