网关超时配置

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

① 配置全局路由超时时间

spring:
  cloud:
    gateway:
      httpclient:
        connect-timeout: 1000
        response-timeout: 10s
  • connect-timeout 必须以毫秒为单位指定连接超时时间。
  • response-timeout 必须指定为 java.time.Duration

② 特定接口配置超时时间

- id: pig-upms      # 唯一的服务 ID
  uri: lb://pig-upms # 注册中心的服务名称,实现负载均衡
  predicates:
  - Path=/admin/demo  #所有业务的请求前缀
  metadata:
    response-timeout: 200
    connect-timeout: 200

可以通过路由的 metadata 以下两个参数配置每个路由超时:

  • connect-timeout 必须以毫秒为单位指定连接超时时间。
  • response-timeout 必须以毫秒为单位指定响应超时时间。

网关统一异常包装

♥️ 获取支持

遇到问题?

如果您在使用过程中遇到任何问题、有功能建议或需求,请点击此卡片前往 Gitee 仓库提交 Issue。