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