Spring Cloud Gateway网关之超时时间配置

API网关
01 Spring Cloud Gateway网关之快速上手
02 Spring Cloud Gateway网关之两种路由配置方式
03 Spring Cloud Gateway网关之跨域支持
04 Spring Cloud Gateway网关之自定义全局过滤器
05 Spring Cloud Gateway网关之自定义路由过滤器
06 Spring Cloud Gateway网关之自定义路由谓词工厂
07 Spring Cloud Gateway网关之超时时间配置
08 Spring Cloud Gateway网关之配置说明
09 Zuul网关之快速上手
10 Zuul网关之路由配置
11 Zuul网关之跨域支持
12 Zuul网关之超时时间配置
13 Zuul网关之自定义过滤器

一 路由超时时间配置

路由超时配置可以为所有路由配置Http超时(响应和连接),并为每个特定路由覆盖Http超时。

二 全局路由超时时间配置

要配置全局http超时,需要配置以下两个参数:

connect-timeout 必须以毫秒为单位指定连接超时时间.
response-timeout 必须指定为java.time.Duration

示例如下:

1
2
3
4
5
6
spring:
cloud:
gateway:
httpclient:
connect-timeout: 1000
response-timeout: 5s

三 每个路由的超时时间配置

可以通过路由的metadata以下两个参数配置每个路由超时:
connect-timeout 必须以毫秒为单位指定连接超时时间.
response-timeout 必须以毫秒为单位指定响应超时时间.

示例如下:

1
2
3
4
5
6
7
8
9
- id: per_route_timeouts
uri: https://example.org
predicates:
- name: Path
args:
pattern: /delay/{timeout}
metadata:
response-timeout: 200
connect-timeout: 200