spring cloud gateway 2 深入了解 - 综述

简介

  • spring cloud gateway 2 基于 Spring Boot 2和 Spring Webflux ,它使用 Netty
    • 注意:由于它使用了Spring Webfluxspring-boot-starter-webflux),所以不再兼容spring-boot-starter-web
  • 对比zuul,spring cloud gateway 支持长连接且提供丰富的路由规则实现(丰富的Predicate和Filter)。

概念

route(路由)

  • spring cloud gateway 的 route 由以下部分组成

Predicate(谓词)

  • 通过Predicate,spring cloud gateway可以让开发人员匹配HTTP请求中的任何内容,例如请求头或参数。
    • spring cloud gateway可以根据HTTP请求中的任何内容进行路由,而不局限于url路径
    • 可以参考下面的图片

Filter(过滤器)

  • 过滤器用于发送和返回请求之前,修改请求和响应

原理图

image.png
  • 图中三个框代表的意义

    • Gateway Client可以是浏览器
    • 中间的大框就是spring cloud gateway的内部工作原理图
    • Proxied Service可以是在eureka等注册中心里注册的服务
  • 官方对这个原理图的描述如下

Clients make requests to Spring Cloud Gateway. If the Gateway Handler Mapping determines that a request matches a Route, it is sent to the Gateway Web Handler. This handler runs sends the request through a filter chain that is specific to the request. The reason the filters are divided by the dotted line, is that filters may execute logic before the proxy request is sent or after. All "pre" filter logic is executed, then the proxy request is made. After the proxy request is made, the "post" filter logic is executed.

  • 翻译成中文大概就是
    • 首先,客户端向Spring Cloud Gateway发出请求。
    • 如果请求与Spring Cloud Gateway中的某个路由匹配(请求匹配到某个处理器),则将请求发送到对应路由的处理器中。
    • 最后过滤器处理请求
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • Spring Cloud为开发人员提供了快速构建分布式系统中一些常见模式的工具(例如配置管理,服务发现,断路器,智...
    卡卡罗2017阅读 134,993评论 19 139
  • Spring Web MVC Spring Web MVC 是包含在 Spring 框架中的 Web 框架,建立于...
    Hsinwong阅读 22,594评论 1 92
  • 微服务架构模式的核心在于如何识别服务的边界,设计出合理的微服务。但如果要将微服务架构运用到生产项目上,并且能够发挥...
    程序员技术圈阅读 2,796评论 10 27
  • 1 最近集中跟几个朋友聊了同一个话题:如果现在已经财务自由了,比如手里有个把亿,你想去做什么。 收到的回答,第一要...
    灯叔说书阅读 881评论 0 2
  • 步骤2:当你阅读每一个资料时,注意你想在写作中提到的观点。 如果作者的文章非常清晰和简洁,复制它们并且用引号精确的...
    Duan__阅读 231评论 0 1