1. 程式人生 > >Spring cloud Netflix中的超時配置

Spring cloud Netflix中的超時配置

一般SpringCloud中超時配置,含Hystrix/Ribbon兩部分:

ribbon:
  ReadTimeout: 120000
  ConnectTimeout: 120000
  
hystrix:
  command:
    default:
      execution:
        isolation:
          strategy: THREAD
          thread:
            timeoutInMilliseconds: 120000

hystrix thread timeout需要比ribbon timeout設定時間長。
ribbon有retry機制,如果timeout設定時間短,則無法retry。

在zuul中,如果使用的是服務發現,ribbon timeout同上。
如果使用的指定URL形式,ribbon timeout需要如下配置:

zuul:
  host:
    connect-timeout-millis: 120000
    socket-timeout-millis: 120000

Zuul官方說明

8.13 Zuul Timeouts If you want to configure the socket timeouts and read timeouts for requests proxied through Zuul, you have two options, based on your configuration: If Zuul uses service discovery, you need to configure these timeouts with the ribbon.ReadTimeout and ribbon.SocketTimeout Ribbon properties. If you have configured Zuul routes by specifying URLs, you need to use zuul.host.connect-timeout-millis

and zuul.host.socket-timeout-millis.