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