一 代码位置
https://github.com/cakin24/spring-cloud-code/tree/master/ch17-3/ch17-3-7-gateway
https://github.com/cakin24/spring-cloud-code/tree/master/ch17-3/ch17-3-service
二 关键代码
server:
port: 8080
spring:
application:
name: spring-cloud-gateway
spring:
cloud:
gateway:
routes:
- id: prefix_route
uri: http://localhost:8071/test/Hystrix?isSleep=true
predicates:
- Path=/test/Hystrix
filters:
- name: Hystrix # Hystrix Filter的名称
args: # Hystrix配置参数
name: fallbackcmd #HystrixCommand的名字
fallbackUri: forward:/fallback #fallback对应的uri
#Hystrix的fallbackcmd的时间
hystrix.command.fallbackcmd.execution.isolation.thread.timeoutInMilliseconds: 5000
logging:
level:
org.springframework.cloud.gateway: TRACE
org.springframework.http.server.reactive: DEBUG
org.springframework.web.reactive: DEBUG
reactor.ipc.netty: DEBUG
三 测试
1 启动ch17-3-7-gateway
2 启动ch17-3-service
3 浏览器输入: http://localhost:8080/test/Hystrix
4 超时后页面显示: