# spring-cloud-test **Repository Path**: zhangtao1812/spring-cloud-test ## Basic Information - **Project Name**: spring-cloud-test - **Description**: No description available - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2019-05-20 - **Last Updated**: 2020-12-19 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README ## Spring Cloud gateway - 协议转换,**路由转发** - 流量聚合,对流量进行监控,**日志**输出 - 作为整个系统的前端工程,对流量进行控制,有**限流**的作用 - 作为系统的前端边界,外部流量只能通过网关才能访问系统 - 可以在网关层做**权限**的判断 - 可以在网关层做缓存 ![avatar](https://raw.githubusercontent.com/spring-cloud/spring-cloud-gateway/master/docs/src/main/asciidoc/images/spring_cloud_gateway_diagram.png) ​ 客户端向Spring Cloud Gateway发出请求。 如果Gateway Handler Mapping确定请求与路由匹配(这个时候就用到**predicate**),则将其发送到**Gateway web handler**处理。 Gateway web handler处理请求时会经过一系列的**过滤器链**。 过滤器链被虚线划分的原因是过滤器链可以在发送代理请求之前或之后执行过滤逻辑。 先执行所有**“pre”过滤器**逻辑,然后进行代理请求。 在发出代理请求之后,收到代理服务的响应之后执行“post”过滤器逻辑。这跟zuul的处理过程很类似。在执行所有“pre”过滤器逻辑时,往往进行了**鉴权**、**限流**、**日志输出**等功能,以及**请求头的更改**、**协议的转换**;转发之后收到响应之后,会执行所有**“post”过滤器**的逻辑,在这里可以响应数据进行了修改,比如响应头、协议的转换等。 #### filter过滤器 如果有多个应用时,往往都需要用于校验的过滤器或拦截器. ![avatar](https://src.windmt.com/img/006tKfTcly1fr43eek154j316c0g4wgz.jpg) 可以通过前置的网关服务来完成这些非业务性质的校验 ![avatar](https://src.windmt.com/img/006tKfTcly1fr43dop520j31j60ni413.jpg) ##### Filter 的生命周期 Spring Cloud Gateway 的 Filter 的生命周期不像 Zuul 的那么丰富,它只有两个:“pre” 和 “post”。 ![avatar](https://src.windmt.com/img/006tKfTcly1fr48yqx3ouj31kw17pn81.jpg) ##### Filter 的分类 Spring Cloud Gateway根据作用范围划分为GatewayFilter和GlobalFilter