Spring Cloud Gateway

Gateway是Spring Cloud 第二代网关,第一代是Zuul。

Spring Cloud Gateway 简介

Spring Cloud Gateway 是什么

Spring Cloud Gateway是Spring官网基于Spring 5.0、 Spring Boot 2.0、Project Reactor等技术开发等网关
Spring Cloud Gateway为微服务架构提供简单、有效且统一的API路由管理方式。
Spring Cloud Gateway基于Filter链提供网关基本功能:安全、监控/埋点、限流等。
Spring Cloud Gateway是替代Netflix Zuul的一套解决方案。

Spring Cloud Gateway 核心概念

Spring Cloud Gateway设计以降低管理成本和安全风险,包含协议适配、协议转发、安全策略(WAF)、防刷、流量、监控日志等功能
下面介绍Spring Cloud Gateway中重要的概念:
Spring Cloud Gateway

  • 路由(route)
    路由信息的组成:
    由一个ID、一个目的URL、一组断言工厂、一组Filter组成
    如果路由断言为真,说明请求URL和配置路由匹配
  • 断言(Predicate)
    Java 8中的断言函数
    Spring Cloud Gateway中的断言函数输入类型是Spring 5.0框架中的ServerWebExchange。Spring Cloud Gateway的断言函数允许开发者去定义匹配来自于Http Request中的任何信息比如请求头和参数
  • 过滤器(Filter)
    一个标准的Spring WebFilter
    Spring Cloud Gateway中的Filter分为两种类型的Filter,分别是Gateway FilterGlobal Filter。过滤器Filter将会对请求和响应进行修改处理。

Spring Cloud Gateway 工作原理

Spring Cloud Gateway

Spring Cloud Gateway 案例

Spring Cloud Gateway 路由断言

Spring Cloud Gateway 内置Filter

相关文章: