Spring Cloud Gateway 和 Feign Client 的异步调用问题

问题描述 投票:0回答:1

我的 Spring Cloud Gateway 设置面临一个问题,其中配置为遍历多个服务的 GET 端点不等待下游服务的响应。具体来说,我有一个 Spring Cloud Gateway 服务,在 Consul 中注册为发现客户端,将请求路由到 portfolio-service。然后,此portfolio-service使用 Feign 客户端来调用 risk-profiler-service中的端点。

下面是我用于路由的谓词。

routes:
    - id: portfolioservice
      uri: lb://portfolioservice
      predicates:
        - Path=${gateway-prefix}/v1/riskManagers/**
      filters:
        - RewritePath=${gateway-prefix}/(?<path>.*), ${gateway-prefix}/$\{path}          
        - name: CircuitBreaker
          args:
            name: portfolioServiceFallback
            fallbackuri: forward:/fallback/portfolioServiceFallback

另外,我在 application.yml 文件中添加了以下属性

spring:
   cloud:
    openfeign:
      client:
        config:
          default:
            readTimeout: 600000
            connectTimeout: 600000

如何确保 Spring Cloud Gateway 等待嵌套服务的响应,尤其是在服务中使用 Feign 客户端时?

任何关于如何正确配置此类设置的见解、建议或示例将不胜感激。

spring-boot spring-cloud-gateway spring-cloud-config spring-cloud-feign
1个回答
0
投票

您可以像这样在网关中添加响应超时

spring.cloud.gateway.httpclient.response-timeout=700s
© www.soinside.com 2019 - 2024. All rights reserved.