2. Introduction to Reactive Programming
Spring Boot 2.0 (Reactive Stack vs Servlet
Stack)
Spring Web Flux Approaches with Demo
3. What is reactiveness?
It must react to its users (responsive).
It must react to failure and stay available (resilient).
It must react to variable load conditions (elastic/scalable).
It must react to inputs (message-driven).
4. What is reactive programming
Reactive Programming manages asynchronous
data flows between producers of data and
consumers that need to react to that data in a
non-blocking manner.
So, Reactive Programming is all about non-
blocking applications that are asynchronous and
event-driven and require a small number of
threads to scale.
10. Benefits of Reactive
Programming
More Flexible
Scalable/resilient
Efficient Use of resources
Less Latency
More tolerance of failures
Highly Responsive
12. Spring Framework 5 embraces Reactive Streams as the contract
for communicating backpressure across async components and
libraries.
Reactive Streams is a specification created through industry
collaboration that has also been adopted in Java 9
as java.util.concurrent.Flow.
Mono: implements Publisher and returns 0 or 1 elements.
Flux: implements Publisher and returns N elements.
13. Spring Web Flux
Spring Framework 5 includes a new spring-webflux module.
The module contains support for reactive HTTP and
WebSocket clients as well as for reactive server web
applications including REST, HTML browser, and WebSocket
style interactions.
Important to know is that there are two ways to use Spring
Web flux.
One using annotations, which is quite similar to Spring MVC,
and one using a functional way.
14. Annotation Based
Programming Model
The annotation based model correlates most to what we have
been doing for years using Spring MVC.
We are able to use all the things we know, but in a reactive
manner. On the outside there is little difference. The biggest
change is on the inside. The underlying implementation is based
on a reactive implementation
of HttpServletRequest and HttpServletResponse
15.
16.
17.
18. JDK 1.8+
Spring 5.0
Spring Boot 2.0
Reactive-Streams
Netty/Jetty/Tomcat/Servlet 3.1+ Container
19. Server name Server API used Reactive Streams support
Netty Netty API Reactor Netty
Undertow Undertow API spring-web: Undertow to
Reactive Streams bridge
Tomcat Servlet 3.1 non-blocking
I/O; Tomcat API to read and
write ByteBuffers vs byte[]
spring-web: Servlet 3.1 non-
blocking I/O to Reactive
Streams bridge
Jetty Servlet 3.1 non-blocking
I/O; Jetty API to write
ByteBuffers vs byte[]
spring-web: Servlet 3.1 non-
blocking I/O to Reactive
Streams bridge
Servlet 3.1 container Servlet 3.1 non-blocking I/O spring-web: Servlet 3.1 non-
blocking I/O to Reactive
Streams bridge