Zuul、Ribbon、Feign、Hystrix使用时的超时时间(timeout)设置问题
基于第一篇的Ribbon、Hystrix使用时的超时时间(timeout)设置问题, 我接触的项目的网关是用zuul转发服务的,那对于这类的该如何配置超时呢,要特别注意哪些呢,我遇到的坑,终于解决了。
工具
Idea
Spring Boot 2.0.5.RELEASE
Eureka 1.9.3
Zuul 1.3.1
Ribbon 2.2.5
Feign 9.5.1
Hystrix 1.5.12
Feign + Hystrix
0. 默认基本配置
最基本的配置,是 Hystrix 自己的一长串配置:hystrix.command.default.execution.isolation.thread.timeoutInMilliseconds
,但在 Feign 模块中,单独设置这个超时时间不行,还要额外设置 Ribbon 的超时时间,比如:
关于 Hystrix 的配置,这里有官方说明
Default Value | 1000 |
---|---|
Default Property | hystrix.command.default.execution.isolation.thread.timeoutInMilliseconds |
Instance Property | hystrix.command.HystrixCommandKey.execution.isolation.thread.timeoutInMilliseconds |
How to Set Instance Default | HystrixCommandProperties.Setter().withExecutionTimeoutInMilliseconds(int value) |
可以看到实例配置中,替代 default 的,是 HystrixCommandKey,这个值在下面会说到
1. 不同实例分别配置
如果更进一步,想把超时时间细分到不同的 service 实例上也可以实现,比如: