Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I consume a non-reactive REST API service using the Spring 5 WebFlux WebClient?

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?

like image 560
Vinod Kumar Avatar asked Jun 13 '18 11:06

Vinod Kumar


People also ask

Should I use WebClient instead of RestTemplate?

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.

Which is the reactive library for consuming restful webservices in Spring?

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.

Is WebClient blocking in Spring?

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.


1 Answers

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.

like image 119
Brian Clozel Avatar answered Sep 18 '22 12:09

Brian Clozel