I am developing microservices using Spring cloud platform where service1 calls multiple other micro services e.g. service2, service3, service 4 etc. These services can be called in parallel and service1 will aggregate the result. Can I use Spring cloud feign (http://cloud.spring.io/spring-cloud-static/Dalston.SR1/#spring-cloud-feign) to generate rest client and call the services asynchronously or Should I use Spring 4 AsyncRestTemplate to call the services asynchronously?
The API that we defined via Feign is synchronous — meaning that it makes blocking calls to the server. Feign allows us to easily define async APIs as well — utilizing CompletableFutures under the hood.
Reactive Feign is great choice for the implementation of non-blocking API clients. It is a reactive version of OpenFeign which supports the creation of API clients without the need to writing implementation code.
When we use the RestTemplate to call the RESTful service, it creates duplication of code that talks to RESTful services. When we define Feign, we need only to define a proxy and define a single method into it. Feign helps us to simplify client code to talk to the RESTful web services.
A central concept in Spring Cloud's Feign support is that of the named client. Each feign client is part of an ensemble of components that work together to contact a remote server on demand, and the ensemble has a name that you give it as an application developer using the @FeignClient annotation.
I have used CompletableFuture to chain async calls to mutiple micro services using feign client however was not eventually successful. Please go through below link for further information. What I understood is - Feign's is not designed for asynchronous invocation or zero-copy i/o.
https://github.com/OpenFeign/feign/issues/361
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