I would like to use 2 approaches(reactive and standard) in one project.
I tried to migrate one REST API endpoint to reactive webflux and test performance before migrate rest of them. But it didn't work. I added router and handler for him, but until I didn't remove spring-boot-starter-web
from dependencies and disable @RestController
I got http 404
code all the time. Is it possible or not? Or should I migrate all project to reactive approach?
Spring WebFlux is a good fit for highly concurrent applications, applications that need to be able to process a large number of requests with as few resources as possible, for applications that need scalability or for applications that need to stream request data in a live manner.
Spring Webflux does not block a thread to handle each request, because no thread is kept waiting for something to be done (e.g. waiting for an answer from a database). As written in 1., it can be blocked while waiting for an answer from a database or from another service that is called via HTTP.
Introduction to Spring Webflux. Spring introduced a Multi-Event Loop model to enable a reactive stack known as WebFlux . It is a fully non-blocking and annotation-based web framework built on Project Reactor which allows building reactive web applications on the HTTP layer.
WebFlux Spring is an awesome and high quality framework, offering an easy way to non-blocking system development. Generally speaking, the technology is mature and production ready.
As explained in the Spring Boot reference documentation, Spring Boot will auto-configure a Spring MVC application if both MVC and WebFlux are available. There are several reasons for this:
Depending on the goal you're trying to achieve, there might be several ways to work on this.
If you'd like to use WebClient
to optimize for multiple, concurrent remote HTTP calls and use Reactor operators, you can keep using Spring MVC annotated controllers and return reactive types as return values (more on this in this Spring Boot talk).
If you'd like to work on pure scalability and latency (so not necessarily raw throughput), then you could start using spring-boot-starter-webflux
and work from there. Note that using blocking APIs (like blocking database calls) is forbidden, and wrapping those with Flux
or Mono
and scheduling that work on separate thread pools will work against you on the performance side.
Finally, if you'd like to use the functional approach provided by Spring WebFlux, then it won't necessarily perform better. It really depends on your use case and how you implement it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With