In this paper, Spring Cloud Finchley.RELEASE version, for example.
RestTemplate timeout
RestTemplate timeout can be set through RestTemplateBuilderl:
@Bean public Residual Template rest template (template builder rest Rest template builder) { return rest template builder .setConnectTimeout (...) .setReadTimeout (...) .build (); }
Ribbon timeout
# Configure global timeouts
Ribbon:
ReadTimeout: 2000 # default 5S
the ConnectTimeout: 1000 # default 2S
# configuration for a specific service
Service-the above mentioned id:
Ribbon:
ReadTimeout: 1000
the ConnectTimeout: 1000
For details, see the default configuration list .
Feign timeout
No details of the document, but some sample code configuration includes:
Feign:
Client:
config:
default:
connectTimeout: 5000 # default 10s
ReadTimeout: 5000 # default 60s
loggerLevel: Basic
Feign default timeout in Request.Options settings.
Note: If you are using Feign Ribbon and at the same time within the application, then the timeout configured to Feign based.
Hystrix timeout
hystrix:
command:
default:
execution:
timeout:
enabled: true #默认true
isolation:
thread:
timeoutInMilliseconds: 5000
As Hystrix fuse, usually when used with other components (e.g. Ribbon):
// pseudo-code is called
hystrix (retry (ribbon ()) )
At this time you need to be set to timeout longer than the other components, or retry mechanism will fail.
Zuul timeout
Since Zuul (Spring Cloud) and used Hystrix Ribbon, so it is configured timeout combination of these two parts. Meanwhile, if the URL routing configuration, but not by way of services (without Ribbon), also you need to configure zuul.host.connect-timeout-millis. Here is the complete configuration:
Zuul:
routes:
Service-the above mentioned id:
path: / the Test / **
serviceId: the SERVICE-ID
ADMIN:
path: / ADMIN / **
url: http://test.com/admin
Host: # timeout for initiating direct URL request configuration (without Ribbon)
max-Total-Connections: 5000
max-per-route-Connections: 500
# for hystrix timeout configuration
hystrix:
the Command:
default:
Execution:
timeout:
Enabled: to true
Isolation:
the Thread:
timeoutInMilliseconds: 5000
# for Ribbon timeout configuration
Ribbon:
ReadTimeout: 1500
the ConnectTimeout: 1000
If you mistakenly Hystrix timeout configured 2s, and Ribbon configured 5s, you see something similar to the following warning in every request:
2019-01-19 17:39:20.981 WARN 36568 --- [io-60362-exec-9] o.s.c.n.z.f.r.s.AbstractRibbonCommand : The Hystrix timeout of 2000ms for the command SERVICE-ID is set lower than the combination of the Ribbon read and connect timeout, 12000ms.
reference
Spring Cloud summarizes the components timeout