Building a CRUD with Spring Webflux
Spring Webflux is a recent version of Spring refactored to allow building non-blocking applications using the project reactor. The main difference is the application server: with Webflux your application will run under Netty which is the “Asynchronous event-driven network application framework”, instead of Tomcat.
Reactive programming
If you are not familiar with this kind of programming approach, you have to know we are building applications based on data-stream and propagation of events/changes of data or conditions.
Project Reactor
It’s an interesting framework that brings reactive programming in Java after javaRx. The pillars of this library are two classes:
- Mono<T> — is a publisher that produces from
0
to1
value ofT
- Flux<T> — is a publisher that produces from
0
toN
values ofT
Both classes follow a basic, but a fundamental principle:
Nothing happens until you subscribe
This means all operations are lazy and they are performed only when the subscribe method is called.
Our Example
To get in the core of reactor we are going to try simple CRUD operations persisting entities on MongoDB. It’s…