Hystrix
是一套完善的服务保护组件, 可以实现服务降级
, 服务熔断
, 服务隔离
等保护措施 使用它可以合理的应对高并发的情况 做到保护服务的效果
1. 导入依赖
<dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-netflix-hystrix</artifactId> </dependency>
2. 在程序启动类添加@EnableHystrix注解, 开启Hystrix
3. 编写方法无法访问时的默认返回数据
String fallback(){ return "服务器繁忙"; }
4. 在接口上添加@HystrixCommand(fallbackMethod = "方法名")注解, 开启Hystrix服务保护
5. 配置application.yml文件
hystrix: command: default: execution: timeout: enabled: false
6. 开启压力测试