SpringBoot FeignClient vs WebClient
Asked Answered
N

3

19

I want to consume a couple of rest services. Before, I used RestTemplate, but now I want to know The main differences between Spring Boot FeignClient and WebClient.

When should they be used?

Nowhere answered 21/4, 2021 at 7:59 Comment(0)
H
17

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)

Haldan answered 1/10, 2021 at 15:40 Comment(0)
S
11

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.

Silvers answered 29/4, 2021 at 12:38 Comment(0)
M
4

WebClient is a non-blocking reactive.

Feign is blocking.

Motherhood answered 3/1, 2022 at 11:56 Comment(1)
Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.Hydrogenolysis

© 2022 - 2024 — McMap. All rights reserved.