Gateway是什么?
springCloud GateWay是基于WebFlux框架实现的,底层是Netty。
SpringCloud GatewWay提供统一路由方式 基于Filter的方式提供了网关的基本功能。例如安全,性能,监控等。
Zuul是基于Sevelet2.5阻塞模型,GateWay是非阻塞模型
属于spring家族,能更好的与springCloud进行整合
路由三大核心概念 路由 断言 过滤器
路由 由id 目标url 一系列断言和过滤器组成,断言为true则路由匹配
断言 开发人员可以匹配HTTP请求中的所有内容(请求头,请求参数等),断言匹配则进行路由
过滤器 指的是spring框架中GateWayFilter实例,可以在请求路由之前或者之后队请求进行修改
过滤器 preFilter可以做参数校验 流量控制 权限校验 日志输出 协议转换等
postFilter可以做响应内容,响应头的修改,流量监控等
下面进入编码
新建 CloudGateWay9527模块
POM
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>cloud2021</artifactId>
<groupId>com.liuxu</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>cloud-gateway-9527</artifactId>
<dependencies>
<!--引入comm工程-->
<dependency>
<groupId>com.liuxu</groupId>
<artifactId>cloud-commons</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<!--eurekaClient-->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-gateway</artifactId>
</dependency>
<
Spring Cloud Gateway详解:路由、过滤器与断言配置

本文介绍了Spring Cloud Gateway作为Spring Cloud生态中的API网关,其基于WebFlux和Netty实现非阻塞模型。内容包括Gateway的核心概念,如路由、断言和过滤器,以及如何通过配置实现路由到服务实例。文中通过实例展示了如何创建路由,利用Path断言和CookieRoutePredicate,并实现全局过滤器进行权限校验。最后,讨论了动态路由和负载均衡的配置。
最低0.47元/天 解锁文章

被折叠的 条评论
为什么被折叠?



