1

Spring Cloud Greenwichspring-cloud-netflix-zuul进入维护模式,所以我正在尝试从 Zuul 迁移到 Spring Cloud Gateway。

使用 Zuul,我有一条类似的路线

zuul:
  routes:
    masterplan_match:
      path: /**/masterplans/**
      serviceId: api-masterplan

我在那里所做的基本上是忽略masterplan接收路径中之前或之后的所有内容并重定向到api-masterplan. 例如,两者/some/path/to/masterplans/masterplans使用同一个 api(原因是masterplans更大实体的子资源,它负责创建新的masterplans,但随后masterplans可以被视为完整的资源,用于诸如GET细节、更新、删除等目的)。

我可以将此配置映射到 Spring Cloud Gateway 吗?查看predicates,可行的似乎是path predicate,但看起来所有匹配器都在单个路径元素上工作(除了WildcardTheRestPathElement,但它只能用作最后一个元素 - 我认为),即:我需要写就像是

spring
    cloud:
      gateway:
        routes:
        - id: masterplan_match
          uri: lb://api-masterplan # Coming from discovery client
          predicates:
          - Path=/some/path/to/masterplans/**, /masterplans/**

我是否遗漏了一些东西,这两条路径可以浓缩成一条吗?

4

1 回答 1

1

Spring Cloud Gateway 自版本以来支持多种模式2.1.0

spring
    cloud:
      gateway:
        routes:
        - id: masterplan_match
          uri: lb://api-masterplan # Coming from discovery client
          predicates:
          - Path=/some/path/to/masterplans/**, /masterplans/**

也可以看看:

在路径谓词中添加对多个路径的支持 #256

主机路由谓词中的多个模式 #589

于 2021-01-02T13:07:13.537 回答