5
5
== Introduction
6
6
The original web framework included in the Spring Framework, Spring Web MVC, was purpose
7
7
built for the Servlet API and Servlet containers. The reactive stack, web framework,
8
- Spring WebFlux, was added later in version 5.0. It is built on a
9
- http://www.reactive-streams.org/[Reactive Streams] API and runs on non-blocking
10
- servers such as Netty, Undertow, and Servlet 3.1+ containers.
8
+ Spring WebFlux, was added later in version 5.0. It is fully non-blocking, supports
9
+ http://www.reactive-streams.org/[Reactive Streams] back pressure, and runs on servers such as
10
+ Netty, Undertow, and Servlet 3.1+ containers.
11
11
12
12
Both web frameworks mirror the names of their source modules
13
13
https://github.com/spring-projects/spring-framework/tree/master/spring-webmvc[spring-webmvc] and
@@ -26,11 +26,11 @@ a `WebTestClient` for testing web endpoints, and WebSocket support.
26
26
27
27
Part of the answer is the need for a non-blocking web stack to handle concurrency with a
28
28
small number of threads and scale with less hardware resources. Servlet 3.1 did provide
29
- an API for non-blocking I/O. However the use of that leads away from using the rest of the
30
- Servlet API which remains synchronous -- `Filter`, `Servlet`, and blocking -- `getParameter`,
31
- `getPart`. On the positive side a new common API foundation makes it possible to support any
32
- server and that is important because of runtimes such as Netty that are well established in
33
- the async, non-blocking space.
29
+ an API for non-blocking I/O. However, using it leads away from the rest of the Servlet API
30
+ where contracts are synchronous ( `Filter`, `Servlet`) or blocking ( `getParameter`,
31
+ `getPart`). This was the motivation for a new common API to serve as a foundation across
32
+ any non-blocking runtime. That is important because of servers such as Netty that are well
33
+ established in the async, non-blocking space.
34
34
35
35
The other part of the answer is functional programming. Much like the addition of annotations
36
36
in Java 5 created opportunities -- e.g. annotated REST controllers or unit tests, the addition
@@ -92,8 +92,8 @@ https://projectreactor.io/docs/core/release/api/reactor/core/publisher/Flux.html
92
92
to work on data sequences of 0..1 and 0..N through a rich set of operators aligned with the
93
93
ReactiveX http://reactivex.io/documentation/operators.html[vocabulary of operators].
94
94
Reactor is a Reactive Streams library and therefore all of its operators support non-blocking back pressure.
95
- Reactor has a strong focus on server-side Java.
96
- It is developed in close collaboration with and feedback from Spring projects .
95
+ Reactor has a strong focus on server-side Java. It is developed in close collaboration
96
+ with Spring.
97
97
98
98
WebFlux requires Reactor as a core dependency but it is interoperable with other reactive
99
99
libraries via Reactive Streams. As a general rule WebFlux APIs accept a plain `Publisher`
@@ -150,10 +150,10 @@ for the same annotation-based programming model in both frameworks makes it easi
150
150
re-use knowledge while also selecting the right tool for the right job.
151
151
152
152
A simple way to evaluate an application is to check its dependencies. If you have blocking
153
- persistence APIs, or networking APIs to use, then Spring MVC is the best choice for common
154
- architectures at least. It is technically feasible with both Reactor and RxJava to perform
155
- blocking calls on a separate thread but you wouldn't be making the most of a non-blocking
156
- web stack.
153
+ persistence APIs (JPA, JDBC), or networking APIs to use, then Spring MVC is the best choice
154
+ for common architectures at least. It is technically feasible with both Reactor and
155
+ RxJava to perform blocking calls on a separate thread but you wouldn't be making the
156
+ most of a non-blocking web stack.
157
157
158
158
If you have a Spring MVC application with calls to remote services, try the reactive `WebClient`.
159
159
You can return reactive types (Reactor, RxJava, <<webflux-reactive-libraries,or other>>)
0 commit comments