上一篇,SpringCloudAlibaba篇(四)整合Dubbo(RPC 分布式服务框架)
文章目录
前言
Spring Cloud 原先整合 Zuul 作为网关组件,Zuul 由 Netflix 公司提供的,现在已经不维护了。后面 Netflix 公司又出来了一个 Zuul2.0 网关,但由于一直没有发布稳定版本,所以 Spring Cloud 等不及了就自己推出一个网关,已经不打算整合 zuul2.0 了。
Spring Cloud Gateway 是 Spring 公司基于 Spring 5.0, Spring Boot 2.0 和 Project Reactor 等技术开发的网关,它旨在为微服务架构提供一种简单有效的统一的 API 路由管理方式。它的目标是替代 Netflix Zuul,其不仅提供统一的路由方式,并且基于 Filter 链的方式提供了网关基本的功能,例如:安全,监控和限流。
GateWay执行流程

1.创建gateway模块

1.1 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>SpringCloudAlibaba2022</artifactId>
<groupId>top.fate</groupId>
<version>1.0.0</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>gateway</artifactId>
<name>${project.artifactId}</name>
<version>${fate.project.version}</version>
<packaging>jar</packaging>
<properties>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
</properties>
<dependencies>

本文介绍了如何在SpringCloud项目中使用Gateway作为微服务网关,替代不再维护的Zuul。首先,详细展示了创建Gateway模块的步骤,包括添加依赖、创建启动类和配置文件,以及在Nacos中配置路由。接着,演示了Gateway整合Sentinel进行流量控制,通过添加依赖和配置文件实现。最后,通过测试接口验证了整合的成功。
最低0.47元/天 解锁文章
3112

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



