65 GateWay 和 Zuul 课程说明
66 GateWay 是什么
67 GateWay 非阻塞异步模型
68 GateWay 工作流程
69 GateWay 9527 搭建
70 GateWay 配置路由两种方式
71 GateWay 配置动态路由
72 GateWay 常用Predicate
73 GateWay 的Filter
65 GateWay 和 Zuul 课程说明
Zuul 被GateWay 替换掉了
66 GateWay 是什么
Zuul 网关 官网
SpringCloud GateWay 官网
SpringCloud GateWay 基于 WebFlux,WebFlux 框架使用了Reactor模式的Netty通信框架。
67 GateWay 非阻塞异步模型
Zuul 1.X 是一个基于 Servlet 2.5 的阻塞架构
68 GateWay 工作流程
gateway 三大理念
1.Predicate
2.Route
3.Filter
gateway 核心:
1.路由转发
2.执行过滤链
filter 分为
pre 可以做日志记录 ,流量监控 , 权限校验 等操作
post 可以做日志记录 ,流量监控 等操作
69 GateWay 9527 搭建
新建网关 GateWay
GateWay网关不需要 spring-boot-starter-web / spring-boot-starter-actuator
不然会报错
测试
http://eureka7001.com:7001/ --查看注册中心
http://localhost:8001/payment/get/2 — 添加网关前的访问方式
http://localhost:9527/payment/get/2 — 添加网关后的访问方式
70 GateWay 配置路由两种方式
http://localhost:9527/payment/lb
71 GateWay 配置动态路由
http://localhost:9527/payment/lb
72 GateWay 常用Predicate
https://cloud.spring.io/spring-cloud-static/spring-cloud-gateway/2.2.1.RELEASE/reference/html/#gateway-request-predicates-factories
获取时间写法
ZonedDateTime zbj= ZonedDateTime.now();
System.out.println(zbj);
curl http://localhost:9527/payment/get/2 -H “X-Request-Id:123”
73 GateWay 的Filter
factory Filter
https://cloud.spring.io/spring-cloud-static/spring-cloud-gateway/2.2.1.RELEASE/reference/html/#gatewayfilter-factories
31 种 filter 示例见上面页面代码
global-filters
https://cloud.spring.io/spring-cloud-static/spring-cloud-gateway/2.2.1.RELEASE/reference/html/#global-filters
http://localhost:9527/payment/lb?uname=z3 ------ ok
http://localhost:9527/payment/lb?uname22=z3 ----- failed
http://localhost:9527/payment/lb ----- failed