I have a written a microservice using Spring 5 WebFlux and trying to consume a non-reactive REST API through it. Is it possbile to consume a non-reactive service using a reactive webclient?
Even on the official Spring documentation, they advise to use WebClient instead. WebClient can basically do what RestTemplate does, making synchronous blocking calls. But it also has asynchronous capabilities, which makes it interesting. It has a functional way of programming, which makes it easy to read as well.
Spring Reactive Web: The spring reactive web provides a reactive feature to our application. Spring Data R2DBC: Provides Reactive Relational Database Connectivity to persist data in SQL stores using Spring Data in reactive applications. Lombok: Java annotation library which helps to reduce boilerplate code.
WebClient Non-Blocking Client. On the other side, WebClient uses an asynchronous, non-blocking solution provided by the Spring Reactive framework. While RestTemplate uses the caller thread for each event (HTTP call), WebClient will create something like a “task” for each event.
Yes, this is possible. From the server's point of view, this is just a regular HTTP client. WebClient
does support streaming and backpressure, but this doesn't change things at the HTTP level.
The backpressure is dealt with at the TCP flow-control level, so the HTTP protocol stays the same.
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