Gateway
1、多个服务
如果开发中有多个服务,怎么让前端或移动端调⽤⼀套接⼝?
2、Gateway是什么
Gateway就是微服务项⽬提供⼀种简单有效的统⼀的 API 路由管理⽅式并且可以对请求进⾏过滤处理。
优点
性能强劲,是Zuul的1.6倍 功能强⼤,内置了很多实⽤的功能,例如转发、监控、限流等设计优雅,容
易扩展
缺点
依赖Netty与WebFlux,不是传统的Servlet编程模型,有⼀定的学习成本不能在Servlet容器下⼯作,也
不能构建成WAR包,即不能将其部署在Tomcat、Jetty等Servlet容器⾥,只能打成jar包执⾏ 不⽀持Spring Boot 1.x, 需2.0及更⾼的版本
3、Gateway解决什么问题
4、Gateway实现服务匹配
Getway核⼼的作⽤:
1.服务路由匹配
2.pom.xml
<dependencies>
<!-- 注册-->
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
<version>2021.1</version>
</dependency>
<!-- -->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-loadbalancer</artifactId>
</dependency>
<!-- gateway -->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-gateway</artifactId>
</dependency>
<!-- 公告 -->
<dependency>
<groupId>com.kou</groupI