2. Lack of etiquette and manners is a huge turn oïŹ.
KnolX Etiquettes
Punctuality
Join the session 5 minutes prior to
the session start time. We start on
time and conclude on time!
Feedback
Make sure to submit a constructive
feedback for all sessions as it is
very helpful for the presenter.
Silent Mode
Keep your mobile devices in silent
mode, feel free to move out of
session in case you need to attend
an urgent call.
Avoid Disturbance
Avoid unwanted chit chat during
the session.
3. Agenda
01 What is reactive System
02 What is Project reactor
03 What is Spring Webflux
04 Salient features of spring webflux
05 Back pressure in spring webflux
06 Installation and Demo
4. What is Reactive System
â Reactive Systems are systems designed
with a reactive architectural pattern that
prioritizes the use of loosely coupled,
flexible, and scalable components.
â Theyâre also designed with failure
resolution in mind to ensure most of the
system will still operate even if one fails.
â Reactive systems focus on: Reactiveness,
Resilience: Elasticity: Message-driven
communication:
5. Blocking and non blocking request
â In a conventional MVC application, whenever a request reaches the server, a
servlet thread is being created and delegated to worker threads to perform various
operations like I/O, database processing, etc.
â In a non-blocking system, all the incoming requests are accompanied by an event
handler and a callback.
â When the handler function completes its process, one of the threads from the pool
fetches the response and passes it to the callback function.
6. What is project reactor?
â Project Reactor is a framework built by
Pivotal and powered by Spring. It
implements reactive API patterns, most
notably the Reactive Streams
specification.
â The main difference between them is that
Fluxes and Monos follow a
publisher-subsciber pattern and
implement backpressure, while the
Stream API does not.
â The main advantage of using Reactor is
that youâre in total control of the data flow:
7. Flux and Mono
â It implements the Publisher interface and, it is just a reactive stream that pushes elements
whenever the subscriber instructs it to do so. It returns 0 to 1 element.
Mono<String> mono = Mono.just("Knoldus");
Mono<String> mono = Mono.empty();
â Mono is a special case in which the reactive stream will either emit only one item or none. It
contains a different set of methods to, for instance, concatenate Mono streams into a Flux. It
returns 0 to N elements.
Flux<String> flux = Flux.just("A", "B", "C");
Flux<String> flux = Flux.fromArray(new String[]{"A", "B", "C"});
Flux<String> flux = Flux.fromIterable(Arrays.asList("A", "B", "C")
8. Reactive Integration
Spring is including Reactor in some of their popular Spring modules, thus enforcing
reactive programming patterns when we use them.
â Spring is including Reactor in some of their popular Spring modules, thus
enforcing reactive programming patterns when we use them.
â Spring Data has also embraced Reactive Patterns through its Reactive module,
with the inclusion of the ReactiveCrudRepository.
9. What is spring webflux
â Spring WebFlux is a fully non-blocking,
annotation-based web framework built on Project
Reactor that makes it possible to build reactive
applications on the HTTP layer.
â WebFlux uses a new router functions feature to
apply functional programming to the web layer
and bypass declarative controllers and
RequestMappings.
â WebFlux requires you to import Reactor as a core
dependency.
10. Salient features of spring webflux
â Router functions
â WebClient
â Reactive Steam API
â Servers
â Concurrency Model
â Spring WebFlux Security
11. Backpressure in spring webflux
Backpressure is the ability of a Consumer to signal the Producer that the rate of
emission is higher than what it can handle.
Backpressure in Reactive Streams
â In Reactive Streams, backpressure also defines how to regulate the transmission of
stream elements.
â Due to the non-blocking nature of Reactive Programming, the server doesnât send the
complete stream at once. It can push the data concurrently as soon as it is available.
12. Handling backpressure
Basically, there are three strategies to follow:
â Send new events only when the subscriber requests them
â Limiting the number of events to receive at the client-side:
â Cancelling the data streaming when the consumer cannot process more events:
13. Logging in spring webflux
â DEBUG level logging in Spring WebFlux is compact, minimal, and human-friendly.
â TRACE level logging generally follows the same principles as DEBUG (and for
example also should not be a firehose) but can be used for debugging any issue.
â In WebFlux, a single request can be run over multiple threads and the thread ID is
not useful for correlating log messages that belong to a specific request. This is why
WebFlux log messages are prefixed with a request-specific ID by default.
â Logging libraries such as SLF4J and Log4J 2 provide asynchronous loggers that
avoid blocking.