Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Communication between Microservices: Spring cloud OpenFeign vs WebClient/RestTemplate

Any idea please about the best way to use for back to back communication ?

spring cloud OpenFeign or WebClient/RestTemplate ?

I think Feign client should be used when spring cloud gateway need to

communicate to other microservices, whereas WebClient/RestTemplate should be used for back to back communication.

Am I wrong ?

like image 969
Amir Choubani Avatar asked Apr 28 '26 14:04

Amir Choubani


1 Answers

WebClient (RestTemplate - deprecated to support WebClient)

  • Supports reactive call

  • underlying HTTP client libraries such as Reactor Netty

  • Part of spring framework - WebFlux || Doc will give you more

  • Comes in 2 flavour - Annotation and functional way

    Personally I found it very useful while working with OAuth2 creating bean webClient, before making call it needs to be authenticated with token, ServerOAuth2AuthorizedClientExchangeFilterFunction will ease each call with just one time configuration

OpenFeign

  • Reactive - need to use 3rd party - com.playtika.reactivefeign
  • Fits best if you want call in blocking way
  • Part of Spring cloud
  • Netflix fully transferred Feign to the open-source community under a new project named OpenFeign
like image 153
Ravi Parekh Avatar answered May 01 '26 05:05

Ravi Parekh