1. Introduction to Feign
Feign is a declarative HTTP client whose purpose is to make remote calls easier. Feign provides the HTTP request
By writing a simple interface and inserting annotations, you can define the parameters, format, address and other information of the HTTP request.
interest. Feign integrates Ribbon (load balancing) and Hystrix (service fusing), so that we no longer need to explicitly use this
two components.
SpringCloudFeign extends support for SpringMVC annotations on the basis of NetflixFeign. Under its implementation, we
Simply create an interface and configure it with annotations to complete the interface binding to the service provider. simulate
SpringCloudRibbon encapsulates the development volume of the service calling client by itself.
Original link: https://blog.csdn.net/m0_51111980/article/details/126672271
2. Feign use
The dependent jar has been introduced when the microservice module was created before
Write an interface and tell springcloud that this interface needs to call a remote service
Here, the member service member wants to call the /coupon/coupon/member/list interface of the coupon service coupon as an example.
To write an interface in the member service center.
First create the storage package name of the remote call interface in the member module, and then create the interface CouponFeignService in the package,
write code in
@FeignClient("gulimall-coupon") gulimall-coupon is the service name registered in nacos
Add to the startup class to @EnableFeignClients
enable remote calls
Write a test method in the controller of the membership service member and call the remote interface
Test the remote call function:
Two microservices are about to be started, but the member microservice reports an error
No Feign Client for loadBalancing defined. Did you forget to include spring-cloud-starter-
loadbalancer?
test:
The check found that the letters were wrongly spelled, mistakes
Test OK