谓词 Weight · SpringCloud微服务实战 · 看云

10.谓词 Weight

导航

重路由谓词工厂采用两个参数:group和weight。权重是按组计算的

本节代码地址


10.1 应用配置

这条路线会将大约80%的流量转发到fw-cloud-ribbon-server,将大约20%的流量转发到fw-cloud-ribbon-server-bak

server:
  port: 8699
spring:
  application:
    name: fw-gateways-gateway
  profiles:
    active: host_route
eureka:
  client:
    service-url:
      defaultZone: http://localhost:8761/eureka/
---
spring:
  cloud:
    gateway:
      routes:
        - id: weight_heigh
          uri: lb://fw-cloud-ribbon-server
          predicates:
            - Weight=group1, 8
        - id: weight_low
          uri: lb://fw-cloud-ribbon-server-bak #修改配置,换一个服务名启动
          predicates:
              - Weight=group1, 2
  profiles: weight_route

10.3 系统启动

Postman 输入localhost:8699/user/2测试
867ec254dc573d26b98967f5853b20ec_MD5.webp

f7ca2a53f7f2d1f2c971c5fad058cc6b_MD5.webp