1.依赖
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-hystrix</artifactId>
<version>2.2.1.RELEASE</version>
</dependency>
2.配置路由
spring:
application:
name: spring-cloud-gateway
cloud:
gateway:
routes:
- id: hystrix_route
uri: http://localhost:8088/
predicates:
- Path=/hystrix/**
filters:
- StripPrefix=1
- name: Hystrix
args:
name: default
fallbackUri: 'forward:/defaultFallback'
name: Hystrix 为 HystrixGatewayFilterFactory 前缀
3.实现降级
@RestController
public class DefaultHystrixController {
@GetMapping("/defaultFallback")
public String defaultFallback(){
return "网关触发熔断降级";
}
}