2024-07-11
한어Русский языкEnglishFrançaisIndonesianSanskrit日本語DeutschPortuguêsΕλληνικάespañolItalianoSuomalainenLatina
So how does server A make a request to service B?
This is the main issue to be addressed in this section.
In this project, the OpenFeign component is used to complete the calls between services. OpenFeign is an encapsulation of Http requests.
OpenFeign is a declarative HTTP client that aims to make remote calls easier.
Feign provides a template for HTTP requests. By writing a simple interface and inserting annotations, you can define the parameters, format, address and other information of the HTTP request.
Feign integrates Ribbon (load balancing) and Hystrix (service fuse), so we no longer need to use these two components explicitly.
SpringCloudFeign extends the support for SpringMVC annotations based on NetflixFeign. Under its implementation, we only need to create an interface and configure it with annotations to complete the interface binding of the service provider. This simplifies the development of SpringCloudRibbon's self-encapsulated service call client.
We will learn how to use OpenFeign with a scenario-based problem.会员服务
To call优惠券服务
An interface that returns the coupon information that the member can use.
The interface of this coupon is as follows. This is an interface used for testing and has no real business logic.
@RequestMapping("member/list")
public R list(){
CouponEntity couponEntity = new CouponEntity();
couponEntity.setCouponName("慢100减80");
return R.ok().put("page", Arrays.asList(couponEntity));
}