spring cloud gateway 是微服务常用网关
网关转发语法
application.properties
spring.cloud.gateway.routes[0].id=url-proxy
spring.cloud.gateway.routes[0].predicates[0]=Path=/**
spring.cloud.gateway.routes[0].uri=http://www.baidu.com
spring.cloud.gateway.routes[0].order=1000000
spring.cloud.gateway.routes[1].id=eureka
spring.cloud.gateway.routes[1].predicates[0]=Host=eureka.robinluo.top
spring.cloud.gateway.routes[1].uri=http://localhost:8765
spring.cloud.gateway.routes[1].order=10000
order 越小 优先级越大
predicates 语法:
After=2018-01-20T06:06:06+08:00[Asia/Shanghai]
请求时间过滤 之后
Before=2018-01-20T06:06:06+08:00[Asia/Shanghai]
请求时间过滤 之前
Between=2018-01-20T06:06:06+08:00[Asia/Shanghai], 2019-01-20T06:06:06+08:00[Asia/Shanghai]
请求时间之间
Cookie=ityouknow, kee.e
cookie 匹配
Header=X-Request-Id, \d+
header 匹配
Host=**.ityouknow.com
域名匹配
Method=GET
请求方式匹配
Path=/foo/{segment}
访问路径匹配
Query=smile
请求参数匹配
RemoteAddr=192.168.1.1/24
ip地址匹配
代码分析
所有predicate 都是继承自org.springframework.cloud.gateway.handler.predicate.RoutePredicateFactory 接口的实现类
After = AfterRoutePredicateFactory
Before = BeforeRoutePredicateFactory
Between = BetweenRoutePredicateFactory
Cookie = CookieRoutePredicateFactory
Header = HeaderRoutePredicateFactory
Host = HostRoutePredicateFactory
Method = MethodRoutePredicateFactory
Path = PathRoutePredicateFactory
ReadBody = ReadBodyRoutePredicateFactory
Query = QueryRoutePredicateFactory
RemoteAddr = RemoteAddrRoutePredicateFactory
Weight = WeightRoutePredicateFactory
PredicateSpec 有所有配置语法