【问题标题】:How to Distribute Routes to multiple YML files in Spring Cloud Gateway?如何在 Spring Cloud Gateway 中将路由分发到多个 YML 文件?
【发布时间】:2020-03-26 08:51:15
【问题描述】:

我目前正在实施 Spring Cloud 希望将我的路由指定到多个文件中,例如:

最初,我们有一个配置有到 A 和 B 休息端点的路由。

Spring Cloud Gateway fronts Rest Endpoint A and Rest Endpoint B 
    - Created YML 1 with routes to A and B (Refer below)

YML 1
----------------
spring:
  cloud:
    gateway:
      routes:
        - id: RouteA
          uri: https://httpbin.org/
          predicates:
            - Path=/status/200
        - id: RouteB
          uri: https://httpbin.org/
          predicates:
            - Path=/status/400

几天后,我需要添加到另一个 Rest Endpoint C 的路由。我不想触及原始配置(YML 1),而是想为 C 创建一个新的 YML 并期望路由 C 附加到 A 和 B 的原始路由(类似于 Apache Httpd WebProxy)。

要拥有多个 YML,我参考以下链接中的建议: Spring Boot and multiple external configuration files

Spring Cloud Gateway fronts Rest Endpoint A, B and C
    - Existing YML 1 with routes to A and B (Refer below)
    - Created YML 2 with route to C (Refer below)
YML 1
----------------
spring:
  cloud:
    gateway:
      routes:
        - id: RouteA
          uri: https://httpbin.org/
          predicates:
            - Path=/status/200
        - id: RouteB
          uri: https://httpbin.org/
          predicates:
            - Path=/status/400

YML 2
-----------------
spring:
  cloud:
    gateway:
      routes:
        - id: RouteC
          uri: https://httpbin.org/
          predicates:
            - Path=/status/500
Expectation 
-----------------------
spring:
  cloud:
    gateway:
      routes:
        - id: RouteA
          uri: https://httpbin.org/
          predicates:
            - Path=/status/200
        - id: RouteB
          uri: https://httpbin.org/
          predicates:
            - Path=/status/400
        - id: RouteC
          uri: https://httpbin.org/
          predicates:
            - Path=/status/500
Actual Outcome 
-------------------------           
spring:
  cloud:
    gateway:
      routes:
        - id: RouteC
          uri: https://httpbin.org/
          predicates:
            - Path=/status/500

Routes(A, B, C) do not get appended, instead it only picks up the latest configuration (YML 2 - Route C) in the property chain                      

如果其他人对如何实现这一点有任何好的想法,请提出建议。 非常欢迎所有帮助和 cmets。

【问题讨论】:

    标签: spring-cloud-gateway


    【解决方案1】:

    我想出的最好的方法(这实际上不是一个解决方案,而是一种妥协)是使用大的 ASCII 标头(带有一些 online tool like patorjk's)。它使浏览更容易,尤其是在使用 Sublime Text 时。

    这远非理想,但我发现现在可以了。

    【讨论】:

    猜你喜欢
    • 2019-10-12
    • 1970-01-01
    • 1970-01-01
    • 2020-07-18
    • 2023-04-02
    • 2019-08-03
    • 2019-03-31
    • 2023-03-09
    • 2019-10-21
    相关资源
    最近更新 更多