简介:

  gateway主要是做路由 负载,过滤 主要是替代zuul 1.x 性能比zuul好 zuul是基于

Servlet ,gateway是基于spring-webflux  用的netty+reactor

 

yml文件

       实现路由 负载 的配置 亲自测试

 

              

 

spring:
  application:
    name: xgyx_gateway
  cloud:
    discovery:
      locator:
        enabled: true
    gateway:
       routes:
       - id: a  #随便定义不重复就好
         uri: lb://xgyx-welfareservice-x  #服务名称
         predicates:
         - Path=/m/**  #前端访问需加入例如 http:ip:port/m
         filters:
         - StripPrefix=1 #访问后端服务过滤掉m 必填否则找不到后端服务也可以在服务加上统一路径
         - name: Hystrix  #熔断
           args:
             name: default
             fallbackUri: forward:/defaultfallback  #熔断后访问路径
       - id: b
         uri: lb://xgyx-welfareservice
         predicates:
         - Path=/welfare/**
         filters:
         - StripPrefix=1
         - name: Hystrix
           args:
             name: default
             fallbackUri: forward:/fallback
#熔断时间
hystrix:
  command:
    default:
      execution:
        isolation:
          strategy:  SEMAPHORE
          thread:
            timeoutInMilliseconds: 300000  #熔断时间

上面是用了两天时间根据官网上的demo和说明自己测的可以使用  上面 stripPrefix 用的是 PrefixPath 过滤器 其他过滤器使用可以看官网

Logo

权威|前沿|技术|干货|国内首个API全生命周期开发者社区

更多推荐