尽管Hystrix已经停止更新,但是经过多年迭代,目前已经是一个比较成熟的产品,所以仍然有比较广泛的应用。
Hystrix在SpringCloud体系的使用也非常简单,下面,我们开始吧!
=============================================================================
仍然是用我们上节的例子。
- 采用spring-cloud-starter的方式引入:
org.springframework.cloud
spring-cloud-starter-netflix-hystrix
- 在application.yml开启hystrix:
feign:
hystrix:
enabled: true
- 在服务启动类加入@EnableHystrix注解,以使系统支持hystrix的功能。
@SpringBootApplication
@MapperScan(“cn.fighter3.mapper”)
@EnableDiscoveryClient
@EnableFeignClients(basePackages = “cn.fighter3.client”)
@EnableHystrix
public class EshopGoodsApplication {
public static void main(String[] args) {
SpringApplication.run(EshopGoodsApplication.class, args);
}
}
- 编写一个StockClientFallback类,实现StockClientFeign接口,这个