一. 服务降级
1.1服务提供端降级
服务端添加依赖
<dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-netflix-hystrix</artifactId> <version>2.2.10.RELEASE</version> </dependency>
1.2启动类添加注解
@EnableHystrix
1.3举个栗子:在controller层方法上添加
@HystrixCommand(fallbackMethod = "showUserInfoFallBack",commandProperties = { @HystrixProperty(name = "execution.isolation.thread.timeoutInMilliseconds",value = "3000")}) //超过3秒钟降级到userInfoListFallBack
- 参数 fallbackMethod 属性用于指定降级方法。
- 参数 execution.isolation.thread.timeoutInMilliseconds 用于设置自身调用超时时间的峰值,峰值内可以正常运行,否则执行降级方法
@GetMapping("/showUserInfo") @HystrixCommand(fallbackMethod = "showUserInfoFallBack",commandProperties = { @HystrixProperty(name