Spring boot reactive WebClient calling legacy endpoint - spring-boot

In a Spring Boot (2.2.2.RELEASE) application, I have reactive endpoints (returning Mono or Flux), each of them is using reactive WebClient for calling another service. This "other" service is legacy (non-reactive) one.
Here is my question:
Is there a benefit of using Webflux (reactive WebClient) if my reactive endpoint is calling this non-reactive endpoint which does blocking stuff?
Is my reactive endpoint still reactive?

If we're talking about HTTP endpoints, we can call them with blocking or non-blocking (asynchronous) clients, but not fully reactive.
If your "new" application is reactive, you have to use non-blocking client (WebClient in your case), otherwise you will block NIO-threads and loose all the advantages of the reactive approach. The fact that the “other” application is blocking doesn't matter, you can still get a less resource-intensive "new" application.

They are
1. Not fully.
2. Your request is not full reactive until you change legacy APIs
Explanation:
End-to-End Reactive pattern only help into to the performance side
Currently you’re using reactive client this helps to connect to server in two way communication.
First set of APIs are reactive so web server layer is now reactive but data layer (Legacy APIs ) not reactive

Related

Spring Boot Reactive WebService

We want to build a rest API to service high request volumes. I'm planning to build it using Spring Reactive(WebFlux) or using Spring Boot Async. We have multiple different clients who will be invoking our service.
Do I need to worry about different clients who will be consuming this service? Meaning if I build the API using Reactive or Async, will all the clients be able to consume this seemlessly?
Meaning if build a reactive Rest API, will the client using RestTemplate be able to consume or do they need to use WebClient only?
Yes, your (not non blocking) clients will still be able to consume a reactive service.

SpringBoot FeignClient vs WebClient

I want to consume a couple of rest services. Before I have used RestTemplate, but now I want to know What is main diffrences of SpringBoot FeignClient and WebClient?
when they should be used?
To be able to answer “when” one needs to understand the capabilities of each.
Spring WebClient is a non-blocking reactive client to make HTTP requests. Hence if you intend to use Spring Reactive Stream API to stream data asynchronously then this is the way to go. Think event-driven architecture. WebClient is part of the Spring WebFlux library.
[Feign]3 is a declarative REST library that uses annotations based architecture with thread-per-request model. This means that the thread will block until the feign client receives the response. The problem with the blocking code is it must wait until the consuming thread completes, hence think memory and CPU cycles.
So use Spring WebClient when needing non-blocking HTTP requests otherwise Feign due to simple usage model.
(Note: There is no reason as to why one cannot use WebClient for blocking operations but Feign is more mature and it’s annotation based model makes it easier)
The main difference is that WebClient supports Reactive calls.
You can achieve that with 3rd party feign clients like https://github.com/Playtika/feign-reactive but basically for a reactive way you should consider using WebClient with some neat async connector like Jetty. On the other hand, If you want a blocking way with minimal hassle then Feign could be your best choice.
WebClient is a non-blocking reactive.
Feign is blocking.

Rate limit web client

I am building a microservice using spring webflux and netty. Internally I use web client to make rest api calls. How can I control rate at which I can call rest api via webclient? I guess backnpressure is only for a single request/reply and does not work across multiple request to my microservice. Amy pointers will be appreciated.Thanks.
Resilience4j has support for non-blocking rate limiting with Reactor.
See: https://resilience4j.readme.io/docs/examples-1#decorate-mono-or-flux-with-a-ratelimiter

Can I use a standalone WebClient without Webflux

I'm developing a reactive service and preparing to use the WebClient to exchange with HTTP APIs,but the service is not in a reactive web stack so how can I use it(WebClient) without depending on Webflux or is there any alternative reactive HTTP client?
Thanks in advance.
I am not sure if I get your question correct: You want to use an inherently reactive class without the reactive lib in which it is contained?
As you can see via the link you put in your question, the WebClient is part of spring-webflux and depends e.g. on reactor.core.publisher.Mono which resides in compile("io.projectreactor:reactor-core"). I can not imagine any scenario in which this WebClient would work or make any sense as you've asked "without depending on Webflux".
Other reactive HTTP clients are:
RxHttpClient
Java HTTP Client introduced in Java 11
May be you could elaborate a little bit more on your needs, why you won't rely on WebFlux or why you want to use a reactive client in a non-reactive stack.

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?
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.

Resources