Spring Cloud Zuul模塊自己就包含了對於hystrix和ribbon的依賴,當咱們使用zuul經過path和serviceId的組合來配置路由的時候,能夠經過hystrix和ribbon的配置調整路由請求的各類時間超時機制。java
ribbon: ConnectTimeout: 1000 ReadTimeout: 2000 MaxAutoRetries: 1 MaxAutoRetriesNextServer: 1
hystrix: command: default: execution: isolation: thread: timeoutInMilliseconds: 60000
這裏須要注意的是hystrix的配置時間應該大於ribbon所有重試時間的總和,上面我配置的是2次重試,包括首次請求,三次時間是6秒spring
引用官方大神的一段說明code
When using Hystrix commands that wrap Ribbon clients you want to make sure your Hystrix timeout is configured to be longer than the configured Ribbon timeout, including any potential
retries that might be made. For example, if your Ribbon connection timeout is one second and
the Ribbon client might retry the request three times, than your Hystrix timeout should
be slightly more than three seconds.
zuul: retryable: true
特別注意zuul的重試配置須要依賴spring的retry,否則的話怎麼配置都是徒勞server
<dependency> <groupId>org.springframework.retry</groupId> <artifactId>spring-retry</artifactId> </dependency>