Spring Cloud feign, based on Netflix feign, also integrates the Spring Cloud ribbon and Spring Cloud Hytrix, which provides a declarative approach to Web service client definition in addition to the power of both.
In the ribbon example, we tried to use Resttemplate to implement an interface call to a dependent service, and Spring Cloud feign was encapsulated on that basis to help us define and implement the definition of a dependent service interface.
First create a new project named Feign-consumer to introduce Eureka and feign dependencies
The main class opens the Feign support function by adding @enablefeignclients annotations
Define HelloService to bind services by specifying a service name through @feignclient ("Hello-service") annotations
Then use SPRINGMVC annotations to bind specific rest interfaces provided by the service
Then create a consumercontroller to implement the call to the feign client
The application.properties is configured as follows
Spring.application.name=feign-consumer
server.port=9002
Eureka.client.serviceurl.defaultzone=http://peer1:1111/eureka/,http://peer2:1112/eureka
Start the project test with the same effect as the Ribbon client load
The service invocation is implemented gracefully and simply by spring Cloud feign in a declarative manner.
Spring Cloud Feign 1 (declarative service invocation feign introduction)