Spring Cloud入门三- Zuul作api-gateway
来源:互联网 发布:平面设计网络课程 编辑:程序博客网 时间:2024/05/19 11:48
Zuul是什么
API Gateway是一个服务器,也可以说是进入系统的唯一节点。这跟面向对象设计模式中的Facade模式很像。API Gateway封装内部系统的架构,并且提供API给各个客户端。它还可能有其他功能,如授权、监控、负载均衡、缓存、请求分片和管理、静态响应处理等。Zuul是Spring cloud的一个组件,作为api-gateway为系统提供反向代理,负载均衡等功能
反向代理
- 新建Spring Cloud项目,在Eureka client依赖的基础上pom.xml引入下面依赖
<dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-zuul</artifactId> </dependency>
- 在***Application.java文件内开启Zuul代理注解。
@EnableZuulProxy@SpringBootApplicationpublic class ZuulServerApplication { public static void main(String[] args) { SpringApplication.run(ZuulServerApplication.class, args); }}
- 修改application.yml文件,设置端口为4444。同时注册到Eureka Server为http://localhost:1111/eureka/。代理指引/api-a/**的请求到service-A的服务上。
spring: application: name: api-gatewayserver: port: 4444zuul: routes: api-a: path: /api-a/** serviceId: service-Aeureka: client: service-url: defaultZone: http://localhost:1111/eureka/
- 启动Eureka Server, Eureka Client, Zuul Server,可以看到注册的服务。
- 在浏览器访问localhost:4444/api-a/discovery,得到Eureka Client 返回的结果。
- Eureka Client输出:
负载均衡
- 在上面的例子里,我们将/api-a/**的所有请求转发到service-A的服务上,假设我们有多个service-A服务,那么,Zuul Server将自动向service-A的所有client进行选择转发。
- 新建一个和Eureka Client 一模一样的项目,修改application.yml的注册端口为3333,启动项目。
- 可以看到两个项目都注册到service-A服务上。
- 访问localhost:4444/api-a/discovery两次,得到相同的结果,而在两个client的输出中都得到结果,说明Zuul在两次请求中分别选择了两个client。
阅读全文
0 0
- Spring Cloud入门三- Zuul作api-gateway
- Spring Cloud入门之Zuul
- Spring Cloud入门3——API Gateway
- API网关服务:Spring Cloud Zuul
- SpringCloud API网关服务(Spring Cloud Zuul)
- Spring Cloud中的API网关服务Zuul
- spring cloud Zuul(API网关服务)
- Spring基础:快速入门spring cloud(4):API网关之Zuul
- 使用Zuul构建API Gateway
- spring cloud Zuul 理解
- spring cloud 之 zuul
- spring cloud zuul
- spring cloud 之 zuul
- Spring Cloud Zuul
- spring-cloud-zuul超时
- Spring Cloud Zuul
- spring cloud zuul
- Spring Cloud OAuth2 & Zuul
- jquery操作radio和checkbox
- Web界面检查点和测试原则
- NSUserDefaults
- 动态申请权限允许后fragment崩溃
- 学生管理系统
- Spring Cloud入门三- Zuul作api-gateway
- python-安装pip以及setuptools
- 鼠标拖拽窗口效果(不允许拖出屏幕的可视区域)
- 前台控制开始日期小于结束日期
- java从FTP下载文件功能
- 5个月ReactNative感受
- linux 下配置opencv3.3.0及 opencv_contrib
- 子元素浮动父容器高度不能自适应的CSS解决方法
- Android 达到Toolbar效果的demo