Gateway 路由规范使用

1.

spring:
  cloud:
    gateway:
      routes:
      - id: after_route
        uri: https://example.org
        predicates:
        - After=2017-01-20T17:42:47.789-07:00[America/Denver]

它指定了一个名为 after_route 的路由,将请求转发到 https://example.org 这个 URI。该路由配置了一个断言谓词 After,它表示只有在请求的时间在指定的时间之后才会匹配该路由。

2.

      routes:
        - id: before_route
          uri: https://example.org
          predicates:
            - Path=/**
            - Before=2017-01-20T17:42:47.789-07:00[America/Denver]

它如果在这个时间之前就访问该uri,否则就访问请求的地址

3.

      routes:
      - id: between_route
        uri: https://example.org
        predicates:
        - Between=2017-01-20T17:42:47.789-07:00[America/Denver], 2017-01-21T17:42:47.789-07:00[America/Denver]

跟上面一样,在时间之间就访问uri

4.

      routes:
      - id: cookie_route
        uri: https://example.org
        predicates:
        - Cookie=chocolate, ch.p

当cookie包含chocolate 或者头是ch  就访问uri

5.

   routes:
      - id: header_route
        uri: https://example.org
        predicates:
        - Header=X-Request-Id, \d+

当请求的头部中存在名为 "X-Request-Id" 的头部,并且该头部的值匹配正则表达式 \d+(表示一个或多个数字字符)时访问uri

6.

  routes:
      - id: host_route
        uri: https://example.org
        predicates:
        - Host=**.somehost.org,**.anotherhost.org

当请求的主机头(Host header)匹配 **.somehost.org**.anotherhost.org 时访问uri

7.

     routes:
      - id: method_route
        uri: https://example.org
        predicates:
        - Method=GET,POST

只有当请求的 HTTP 方法为 GET 或 POST 时,才会访问uri

8.

      routes:
      - id: path_route
        uri: https://example.org
        predicates:
        - Path=/red/{segment},/blue/{segment}

当请求的路径是以 /red//blue/ 开头,并且后面紧跟一个路径段时,访问uri 

9.

      routes:
      - id: query_route
        uri: https://example.org
        predicates:
        - Query=green

当请求的查询参数中包含名为 green 的参数时,访问uri

10.

      routes:
      - id: remoteaddr_route
        uri: https://example.org
        predicates:
        - RemoteAddr=192.168.1.1/24

当请求的远程地址为 192.168.1.1 或者属于 192.168.1.1 子网的地址时,访问uri 

11.

      routes:
      - id: weight_high
        uri: https://weighthigh.org
        predicates:
        - Weight=group1, 8
      - id: weight_low
        uri: https://weightlow.org
        predicates:
        - Weight=group1, 2

 如果请求的权重为8,则会路由到 https://weighthigh.org;如果请求的权重为2,则会路由到 https://weightlow.org

  • 11
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值