GuLi Mall-SpringCloud-OpenFeign Test Remote Call

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 @EnableFeignClientsenable 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?

No Feign Client for loadBalancing defined. Did you forget to include spring-cloud-starter-loadbalanc_Hokkaido Lover's Blog-CSDN Blog

nested exception is java.lang.IllegalStateException: No Feign Client for loadBalancing defined._#晚来天君雪的博客-CSDN Blog

test:

The check found that the letters were wrongly spelled, mistakes

Test OK 

 

Guess you like

Origin blog.csdn.net/ZHOU_VIP/article/details/129094400