Microservices Communication – Feign Client

 Microservices Communication – Feign Client


Spring cloud OpenFeign provides OpenFeign Integration for spring boot apps through auto configuration and binding to the spring environment

Without feign client in spring boot application, we can use Rest Template to call user service. To use Feign client we need to add spring-cloud-starter-OpenFeign dependency in pom.xml

In our project, if one micro-service accesses another microservice then is called inter-service communication

  • ·         Rest Client (External Communication)
  • ·         Web Client(External Communication)
  • ·         Feign Client(Internal Communication)

When we use feign client we do need to configure API URL to access.

Using the API name we can access API (Feign client will get API URL from Service Registry)

Feign Client is part of Spring Cloud Netflix Libraries

Open Feign is declarative Rest client. It makes writing web service clients easier. Just create an interface and add annotation on the interface

The development process for feign Client

  • ·         Select existing project (accounts)
  • ·         Add dependency

      Spring-cloud-starter-feign

  • ·         Add annotation in entry point for spring boot application

        @EnableFeignClients(“package name”)

  1. ·         Create a FeignClient interface and annotate with @FeignClient and pass attribute name and URL

         Create target API Request URL (using JAX-RS annotations)

 

Step 1

Add Dependency



Step 2

Add annotation in entry point for spring boot application

 




Step 3

To Fetch the card's microservice data from the account service create a Separate package as Client



 

In CardsFeignClient



Create a client package for CardsDTO in Customer microservices



Create a Package for ICustomerService

CustomerServiceImpl.java


CustomerDetailsDTO.java

 

Result



Comments

Popular posts from this blog

Rest API- Swagger Documentation

Service Discovery - Eureka Server and Client