第二章 微服务网关基础组件 - zuul入门
一、zuul简介
1、作用
zuul使用一系列的filter实现以下功能
- 认证和安全 - 对每一个resource进行身份认证
- 追踪和监控 - 实时观察后端微服务的TPS、响应时间,失败数量等准确的信息
- 日志 - 记录所有请求的访问日志数据,可以为日志分析和查询提供统一支持
- 动态路由 - 动态的将request路由到后端的服务上去
- 压力测试 - 逐渐的增加访问集群的压力,来测试集群的性能
- 限流 - allocating capacity for each type of request and dropping requests that go over the limit
- 静态响应 - 直接在网关返回一些响应,而不是通过内部的服务返回响应
2、组件:
- zuul-core:library which contains the core functionality of compiling and executing Filters
- zuul-netflix:library which adds other NetflixOSS components to Zuul - using Ribbon for routing requests, for example.
3、例子:
- zuul-simple-webapp:webapp which shows a simple example of how to build an application with zuul-core
- zuul-netflix-webapp:webapp which packages zuul-core and zuul-netflix together into an easy to use package
github地址:https://github.com/Netflix/zuul/
二、zuul filter
1、关键元素
- Type:most often defines the stage during the routing flow when the Filter will be applied (although it can be any custom string)
- 值可以是:pre、route、post、error、custom
- Execution Order: filter执行的顺序(applied within the Type, defines the order of execution across multiple Filters)
- Criteria:filter执行的条件(the conditions required in order for the Filter to be executed)
- Action: filter执行的动作(the action to be executed if the Criteria is met)
注意点:
- filters之间不会直接进行通讯交流,他们通过一个RequestContext共享一个state
- 该RequestContext对于每一个request都是唯一的
- filter当前使用groovy来写的,也可以使用java
- The source code for each Filter is written to a specified set of directories on the Zuul server that are periodically polled for changes
- zuul可以动态的read, compile, and run these Filters
- 被更新后的filter会被从disk读取到内存,并动态编译到正在运行的server中,之后可以用于其后的每一个请求(Updated filters are read from disk, dynamically compiled into the running server, and are invoked by Zuul for each subsequent request)
2、filter type(与一个典型的request的生命周期相关的filter type)
- PRE Filters
- 执行时机: before routing to the origin.
- 这类filter可能做的事
- request authentication
- choosing origin servers(选机器)
- logging debug info.
- 限流
- ROUTING Filters
- 这类filter可能做的事:真正的向service的一台server(这台server是pre filter选出来的)发请求,handle routing the request to an origin,This is where the origin HTTP request is built and sent using Apache HttpClient or Netflix Ribbon.
- POST Filters
- 执行时机:after the request has been routed to the origin
- 这类filter可能做的事
- adding standard HTTP headers to the response
- gathering statistics and metrics
- streaming the response from the origin to the client
- ERROR Filters
- 执行时机:其他三个阶段任一阶段发生错误时执行(when an error occurs during one of the other phases)
- CUSTOM Filters
- 沿着默认的filter流,zuul允许我们创建一些自定义的Filter type,并且准确的执行他们。
- 例如:我们自定义一个STATIC type的filter,用于从zuul直接产生响应,而不是从后边的services(we have a custom STATIC type that generates a response within Zuul instead of forwarding the request to an origin)
三、zuul request lifecycle(filter流)
说明:对应(二)的filter type来看
四、zuul核心架构
zuul的核心就是:filter、filter流与核心架构。这些在下一章会以代码的形式做展示。
第二章 微服务网关基础组件 - zuul入门相关推荐
- 《深入理解 Spring Cloud 与微服务构建》第二章 微服务应该具备的功能
<深入理解 Spring Cloud 与微服务构建>第二章 微服务应该具备的功能 文章目录 <深入理解 Spring Cloud 与微服务构建>第二章 微服务应该具备的功能 一 ...
- 第一章 微服务网关 - 入门
一.什么是服务网关 服务网关 = 路由转发 + 过滤器 1.路由转发:接收一切外界请求,转发到后端的微服务上去: 2.过滤器:在服务网关中可以完成一系列的横切功能,例如权限校验.限流以及监控等,这些都 ...
- 第五章 微服务网关Spring Cloud Gateway
5.1 微服务网关简介 第三章我们介绍了通过Spring Cloud LoadBalancer实现了微服务之间的调⽤和负载均衡,以及使⽤Spring Cloud OpenFeign声明式调⽤,那我们的 ...
- Spring Cloud 微服务网关Gateway组件
一.网关介绍 大家都知道在微服务架构中,一个系统会被拆分为多个微服务,那么作为客户端如何去调用这么多的微服务呢?如果没有网关的存在,我们只能在客户端记录每个微服务的地址,然后分别去用. 这样的架构会存 ...
- 微服务网关总结之 —— zuul
前言 随着微服务的盛行和广泛的使用,选择一套完整的微服务架构解决方案是作为技术选型的前置条件,不管是基于dubbo的或是spring-cloud,还是基于alibaba的升级版cloud的微服务,应用 ...
- 微服务网关spring cloud gateway入门详解
1.API网关 API 网关是一个处于应用程序或服务( REST API 接口服务)之前的系统,用来管理授权.访问控制和流量限制等,这样 REST API 接口服务就被 API 网关保护起来,对所有的 ...
- Zuul微服务网关、容错与监控、Zuul路由端点、路由配置、Zuul上传文件、Zuul过滤器、Zuul异常处理、Zuul回退、Zuul聚合微服务
一.为什么要使用微服务网关 二.Zuul 1.编写Zuul微服务网关 2.Zuul的Hystrix容错与监控 3.Zuul的路由端点 4.路由配置 1.自定义指定微服务的访问路径 2.忽略指定微服务 ...
- SpringCloud—— 微服务网关GateWay
目录 1.GateWay网关概述 1.1.什么是GateWay? 1.2.为什么要使用微服务网关? 1.3.Zuul与GateWay网关的区别? 2.快速入门 2.1.创建项目 2.2.配置yml文件 ...
- [菜鸟SpringCloud实战入门]第九章:服务网关Zuul体验
前言 欢迎来到菜鸟SpringCloud实战入门系列(SpringCloudForNoob),该系列通过层层递进的实战视角,来一步步学习和理解SpringCloud. 本系列适合有一定Java以及Sp ...
最新文章
- RDKit | 通过分析活性化合物确定指标阈值
- java判断一个单向链表是否有环路
- Android关机流程源码分析
- 模仿Spring实现一个类管理容器
- Java面试之锁-读写锁
- 嘿嘿,我就不信搞不定你--Dynamo
- python代码写好了怎么运行-python的代码写在哪里,怎么样运行python代码
- 列表的增删改查和嵌套, 元组, range
- google四件套之Dagger2。从入门到爱不释手,之:Dagger2进阶知识及在Android中使用
- Windows上传文件到CentOS系统
- 数据挖掘模型中的IV和WOE详解
- 计算机无法添加本地策略组,解决win10找不到本地组策略和本地用户的方法
- lpush rpush 区别_php-redis中文参考手册_list容器相关_lPush_rPush_lPushx_rPu...
- lol刷金币python脚本_用Python写王者荣耀刷金币脚本
- kuberneters集群发布内部服务详解
- 一键合并多个Excel文档
- 苹果macOS Big Sur 11.4 正式版发布
- git push origin HEAD
- java马斯京根法计算汇流系数P
- 修身修心的1000+篇文章总结
热门文章
- ​CPU将进入新时代:押注计算芯片的极限协同设计
- 为了研究因果关系,原来科学家在这么多方向上都有尝试
- 未来的设计:我们正在进入“计算设计”时代
- AI新方向: 科学家们暂停模仿“人脑”,公布了新路线图
- 在人工智能时代,我们更需要理解自己的智能 | 艾伦脑科学研究所所长克里斯托夫·科赫STEP峰会演讲实录
- 总监调岗至前台,企业被判赔偿26万,法院:“侮辱性调岗”违法!
- 10 年 IT 老兵给新人程序员的几点建议
- 我拍了拍 Redis,没想到被移出了群聊......
- 为了提升续航,马斯克又引发一场“造芯”革命,华为比亚迪已进场
- 开玩笑写代码获奥斯卡?计算机图形专家这样 5 次捧回大奖!