代码之家  ›  专栏  ›  技术社区  ›  ThanksForAllTheFish

Spring云网关匹配多路径元素

  •  1
  • ThanksForAllTheFish  · 技术社区  · 6 年前

    格林威治春云酒店 spring-cloud-netflix-zuul 在维护模式下,所以我尝试从Zuul迁移到springcloudgateway。

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

    我在那里做的基本上是忽略了之前或之后发生的一切 masterplan 并重定向到 api-masterplan . 例如,两者 /some/path/to/masterplans /masterplans 转到相同的api(原因是 masterplans 是更大实体的子资源,负责创建新的 ,但是 可以被视为完全成熟的资源 GET

    我能把这个配置映射到SpringCloudGateway吗?看着 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/**
    

    我是不是错过了什么,这两条路能浓缩成一条?

    0 回复  |  直到 6 年前
        1
  •  0
  •   iceqing    4 年前

    springcloudgateway版本以来支持多种模式 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/**
    

    另请参见:

    Add support for multiple paths in path predicate #256

    Multiple patterns in Host Route Predicate #589

    推荐文章