熬夜肝了这篇Spring Cloud Gateway的功能及综合使用
前言
SpringCloud 是微服务中的翘楚,最佳的落地方案。
Spring Cloud Gateway 是 Spring Cloud 新推出的网关框架,之前是 Netflix Zuul。网关通常在项目中为了简化
前端的调用逻辑,同时也简化内部服务之间互相调用的复杂度;具体作用就是转发服务,接收并转发所有内外
部的客户端调用;其他常见的功能还有权限认证,限流控制等等。
本博客会提到网关的基本转发功能,熔断功能,限流功能以及功能的综合使用。
2021年Java真题面试文档分享给大家,下面是一张springcloud的技术点整理:
源码
GitHub地址:https://github.com/intomylife/SpringCloud
环境
JDK 1.8.0 +
Maven 3.0 +
SpringBoot 2.0.3
SpringCloud Finchley.RELEASE
Redis 3.0 +
开发工具
IntelliJ IDEA
正文
commons 工程
commons 工程 - 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"><modelVersion>4.0.0</modelVersion><!-- 三坐标 --><groupId>com.zwc</groupId><artifactId>springcloud-gateway-commons</artifactId><version>1.0</version><!-- 工程名称和描述 --><name>springcloud-gateway-commons</name><description>公用工程</description><!-- 打包方式 --><packaging>jar</packaging><!-- 在 properties 下声明相应的版本信息,然后在 dependency 下引用的时候用 ${} 就可以引入该版本 jar 包了 --><properties><!-- 编码 --><project.build.sourceEncoding>UTF-8</project.build.sourceEncoding><!-- jdk --><java.version>1.8</java.version><!-- SpringBoot --><platform-bom.version>Cairo-SR3</platform-bom.version><!-- SpringCloud --><spring-cloud-dependencies.version>Finchley.RELEASE</spring-cloud-dependencies.version></properties><!-- 加入依赖 --><dependencies></dependencies><!-- 依赖 jar 包版本管理的管理器 --><!-- 如果 dependencies 里的 dependency 自己没有声明 version 元素,那么 maven 就此处来找版本声明。 --><!-- 如果有,就会继承它;如果没有就会报错,告诉你没有版本信息 --><!-- 优先级:如果 dependencies 里的 dependency 已经声明了版本信息,就不会生效此处的版本信息了 --><dependencyManagement><dependencies><!-- SpringBoot --><dependency><groupId>io.spring.platform</groupId><artifactId>platform-bom</artifactId><version>${platform-bom.version}</version><type>pom</type><scope>import</scope></dependency><!-- SpringCloud --><dependency><groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-dependencies</artifactId><version>${spring-cloud-dependencies.version}</version><type>pom</type><scope>import</scope></dependency></dependencies></dependencyManagement><!-- 插件依赖 --><build><plugins><plugin><groupId>org.springframework.boot</groupId><artifactId>spring-boot-maven-plugin</artifactId></plugin></plugins></build></project>
配置一些共用依赖
commons 工程 - 项目结构
service 工程
**① 此工程下有四个模块:一个注册中心,一个网关以及两个提供者
② 两个提供者除端口不一致以外,其他代码基本一致
registry-service(注册中心)
registry-service - 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"><modelVersion>4.0.0</modelVersion><!-- 继承父 --><parent><groupId>com.zwc</groupId><artifactId>springcloud-gateway-service</artifactId><version>1.0</version></parent><!-- 三坐标 --><groupId>com.zwc</groupId><artifactId>springcloud-gateway-registry-service</artifactId><version>1.0</version><!-- 工程名称描述 --><name>springcloud-gateway-registry-service</name><description>注册中心</description><!-- 打包方式 --><packaging>jar</packaging><!-- 在 properties下声明相应的版本信息,然后在dependency下引用的时候用 ${} 就可以引入该版本jar包了 --><properties></properties><!-- 加入依赖 --><dependencies><!-- 服务注册中心 --><dependency><groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-starter-netflix-eureka-server</artifactId></dependency></dependencies><!-- 插件依赖 --><build><plugins><plugin><groupId>org.springframework.boot</groupId><artifactId>spring-boot-maven-plugin</artifactId></plugin></plugins></build></project>
主要加入 spring-cloud-starter-netflix-eureka-server 依赖
registry-service - application.yml 配置文件
#端口
server:port: 8761#应用名称
spring:application:name: eureka-servereureka:instance:# 使用 ip 代替实例名prefer-ip-address: true# 实例的主机名hostname: ${spring.cloud.client.ip-address}# 实例的 ID 规则instance-id: ${spring.cloud.client.ip-address}:${spring.application.name}:${server.port}client:# 是否向注册中心注册自己registerWithEureka: false# 是否向注册中心获取注册信息fetchRegistry: falseserviceUrl:# 注册中心地址defaultZone: http://${eureka.instance.hostname}:${server.port}/eureka/
这里使用了默认的 8761 端口,当然也可以更改,不过在发现调用服务端的注册中心地址端口要与它一致
registry-service - 启动类
package com.zwc;import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer;@SpringBootApplication
@EnableEurekaServer
public class SpringcloudGatewayRegistryServiceApplication {public static void main(String[] args) {SpringApplication.run(SpringcloudGatewayRegistryServiceApplication.class, args);}}
在启动类中添加 @EnableEurekaServer 注解表示此工程是注册中心
registry-service - 启动项目
- 项目启动成功后访问 http://localhost:8761/ 即可看到 eureka-server 主页面
注:由于服务工程 A 和服务工程 B 除端口不一致以外,其他代码基本一致,所以服务工程 B 不再赘述
a-service(服务工程 A)
a-service - 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"><modelVersion>4.0.0</modelVersion><!-- 继承父 --><parent><groupId>com.zwc</groupId><artifactId>springcloud-gateway-a-service</artifactId><version>1.0</version></parent><!-- 三坐标 --><groupId>com.zwc</groupId><artifactId>springcloud-gateway-a-service-core</artifactId><version>1.0</version><!-- 工程名称描述 --><name>springcloud-gateway-a-service-core</name><description>服务工程 - A 核心</description><!-- 打包方式 --><packaging>jar</packaging><!-- 在 properties下声明相应的版本信息,然后在dependency下引用的时候用 ${} 就可以引入该版本jar包了 --><properties></properties><!-- 加入依赖 --><dependencies><!-- commons工程 依赖 --><dependency><groupId>com.zwc</groupId><artifactId>springcloud-gateway-commons</artifactId><version>1.0</version></dependency><!-- api工程 依赖 --><dependency><groupId>com.zwc</groupId><artifactId>springcloud-gateway-a-service-api</artifactId><version>1.0</version></dependency><!-- springboot web 依赖 --><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-web</artifactId></dependency><!-- 提供者消费者 --><dependency><groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-starter-netflix-eureka-client</artifactId></dependency></dependencies><!-- 插件依赖 --><build><plugins><plugin><groupId>org.springframework.boot</groupId><artifactId>spring-boot-maven-plugin</artifactId></plugin></plugins></build></project>
加入spring-cloud-starter-netflix-eureka-client依赖
a-service - application.yml 配置文件
#端口
server:port: 9000#应用名称
spring:application:name: gateway-serviceeureka:instance:# 使用 ip 代替实例名prefer-ip-address: true# 实例的主机名hostname: ${spring.cloud.client.ip-address}# 实例的 ID 规则instance-id: ${spring.cloud.client.ip-address}:${spring.application.name}:${server.port}client:serviceUrl:# 注册中心地址defaultZone: http://${eureka.instance.hostname}:8761/eureka/
注意此处配置注册中心地址的端口为 8761 也就是上面注册中心工程配置的端口
a-service - controller 前端控制器(提供服务)
package com.zwc.a.controller;import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;/** @ClassName ASayHelloController* @Desc TODO Say Hello* @Date 2019/5/20 23:24* @Version 1.0*/
@RestController
public class ASayHelloController {/** @ClassName ASayHelloController* @Desc TODO 读取配置文件中的端口* @Date 2019/5/20 23:24* @Version 1.0*/@Value("${server.port}")private String port;/** @ClassName ASayHelloController* @Desc TODO Say Hello* @Date 2019/5/20 23:24* @Version 1.0*/@RequestMapping("/hello")public String hello(){return "Hello!I'm a. port:" + port;}/** @ClassName ASayHelloController* @Desc TODO 接收从网关传入的参数* @Date 2019/6/23 16:28* @Version 1.0*/@RequestMapping("/name")public String name(String name){return "My name is " + name + ". aaa";}/** @ClassName ASayHelloController* @Desc TODO 接收从网关传入的参数* @Date 2019/6/23 16:52* @Version 1.0*/@RequestMapping("/age")public String age(String age){return "I am " + age + " years old this year. aaa";}/** @ClassName ASayHelloController* @Desc TODO 接收从网关传入的参数* @Date 2019/6/29 22:00* @Version 1.0*/@RequestMapping("/routeAll")public String routeAll(String pass) {return "Can I pass? " + pass + "! port:" + port;}}
提供输出字符串服务,供网关调用
a-service - 启动类
package com.zwc;import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.netflix.eureka.EnableEurekaClient;@SpringBootApplication
@EnableEurekaClient
public class SpringcloudGatewayAServiceCoreApplication {public static void main(String[] args) {SpringApplication.run(SpringcloudGatewayAServiceCoreApplication.class, args);}}
添加 @EnableEurekaClient 注解表示此工程可以向注册中心提供服务
a-service - 启动项目
- 刷新 http://localhost:8761/(注册中心)可以看到服务已经被注册进来了
2. 项目启动成功后访问:http://localhost:9000/hello
输出内容:‘Hello!I’m a. port:9000’
同样启动服务工程 B后,刷新 http://localhost:8761/(注册中心)
项目启动成功后访问:http://localhost:9001/hello
输出内容:‘Hello!I’m b. port:9001’
其他接口是下面网关服务启动后转发调用的,也是本博客的重头戏
master-service(网关)
master-service - 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"><modelVersion>4.0.0</modelVersion><!-- 继承父 --><parent><groupId>com.zwc</groupId><artifactId>springcloud-gateway-service</artifactId><version>1.0</version></parent><!-- 三坐标 --><groupId>com.zwc</groupId><artifactId>springcloud-gateway-master-service</artifactId><version>1.0</version><!-- 工程名称描述 --><name>springcloud-gateway-master-service</name><description>Spring Cloud Gateway 服务网关</description><!-- 打包方式 --><packaging>jar</packaging><!-- 在 properties下声明相应的版本信息,然后在 dependency 下引用的时候用 ${} 就可以引入该版本 jar 包了 --><properties><!-- ali json --><fastjson.version>1.2.47</fastjson.version></properties><!-- 加入依赖 --><dependencies><!-- 提供者消费者 --><dependency><groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-starter-netflix-eureka-client</artifactId></dependency><!-- gateway --><dependency><groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-starter-gateway</artifactId></dependency><!-- redis --><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-data-redis-reactive</artifactId></dependency><!-- hystrix --><dependency><groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-starter-netflix-hystrix</artifactId></dependency><!-- ali json依赖 --><dependency><groupId>com.alibaba</groupId><artifactId>fastjson</artifactId><version>${fastjson.version}</version></dependency></dependencies><!-- 插件依赖 --><build><plugins><plugin><groupId>org.springframework.boot</groupId><artifactId>spring-boot-maven-plugin</artifactId></plugin></plugins></build></project>
加入spring-cloud-starter-netflix-eureka-client 依赖:提供和注册服务
加入spring-cloud-starter-gateway 依赖:gateway
加入spring-boot-starter-data-redis-reactive 依赖:结合 Redis 限流
加入spring-cloud-starter-netflix-hystrix 依赖:熔断器
master-service - application.yml 配置文件
#端口
server:port: 8000spring:profiles:# 指定配置# route_simple:简单尝试# route_stripPrefix:截取请求# route_uri:转发指定地址并传入参数# route_addRequestParameter:转发指定服务并传入参数# route_hystrix:熔断# route_requestRateLimiter:限流# route_all:综合active: route_simple---spring:# 配置文件名称,用来标识不同环境的配置。由 spring.profiles.active 的值来决定使用哪组配置。## 简单尝试profiles: route_simpleapplication:# 应用名称name: gateway-mastercloud:gateway:discovery:locator:# 是否和服务注册与发现组件结合,设置为 true 后可以直接使用应用名称调用服务enabled: true# 路由(routes:路由,它由唯一标识(ID)、目标服务地址(uri)、一组断言(predicates)和一组过滤器组成(filters)。filters 不是必需参数。)routes:# 路由标识(id:标识,具有唯一性) 简单尝试- id: route_simple# 目标服务地址(uri:地址,请求转发后的地址)uri: https://www.zouwencong.com# 路由条件(predicates:断言,匹配 HTTP 请求内容)predicates:## 转发地址格式为 uri/archive- Path=/archiveeureka:instance:# 使用 ip 代替实例名prefer-ip-address: true# 实例的主机名hostname: ${spring.cloud.client.ip-address}# 实例的 ID 规则instance-id: ${spring.cloud.client.ip-address}:${spring.application.name}:${server.port}client:serviceUrl:# 注册中心地址defaultZone: http://${eureka.instance.hostname}:8761/eureka/logging:level:# log 级别org.springframework.cloud.gateway: debug---spring:# 配置文件名称,用来标识不同环境的配置。由 spring.profiles.active 的值来决定使用哪组配置。## 截取请求profiles: route_stripPrefixapplication:# 应用名称name: gateway-mastercloud:gateway:discovery:locator:# 是否和服务注册与发现组件结合,设置为 true 后可以直接使用应用名称调用服务enabled: true# 路由(routes:路由,它由唯一标识(ID)、目标服务地址(uri)、一组断言(predicates)和一组过滤器组成(filters)。filters 不是必需参数。)routes:# 路由标识(id:标识,具有唯一性) 截取请求- id: route_simple# 目标服务地址(uri:地址,请求转发后的地址)uri: https://www.zouwencong.com# 路由条件(predicates:断言,匹配 HTTP 请求内容)predicates:## 转发地址格式为 uri/archive,/str 部分会被下面的过滤器给截取掉- Path=/str/archivefilters:## 截取路径位数- StripPrefix=1eureka:instance:# 使用 ip 代替实例名prefer-ip-address: true# 实例的主机名hostname: ${spring.cloud.client.ip-address}# 实例的 ID 规则instance-id: ${spring.cloud.client.ip-address}:${spring.application.name}:${server.port}client:serviceUrl:# 注册中心地址defaultZone: http://${eureka.instance.hostname}:8761/eureka/logging:level:# log 级别org.springframework.cloud.gateway: debug---spring:# 配置文件名称,用来标识不同环境的配置。由 spring.profiles.active 的值来决定使用哪组配置。## 转发指定地址并传入参数profiles: route_uriapplication:# 应用名称name: gateway-mastercloud:gateway:discovery:locator:# 是否和服务注册与发现组件结合,设置为 true 后可以直接使用应用名称调用服务enabled: true# 路由(routes:路由,它由唯一标识(ID)、目标服务地址(uri)、一组断言(predicates)和一组过滤器组成(filters)。filters 不是必需参数。)routes:# 路由标识(id:标识,具有唯一性) 转发指定地址并传入参数- id: route_uri# 目标服务地址(uri:地址,请求转发后的地址)uri: http://localhost:9000# 路由条件(predicates:断言,匹配 HTTP 请求内容)predicates:## 匹配 GET 请求- Method=GET# 过滤器(filters:过滤器,过滤规则)filters:## 添加指定参数- AddRequestParameter=name, zwceureka:instance:# 使用 ip 代替实例名prefer-ip-address: true# 实例的主机名hostname: ${spring.cloud.client.ip-address}# 实例的 ID 规则instance-id: ${spring.cloud.client.ip-address}:${spring.application.name}:${server.port}client:serviceUrl:# 注册中心地址defaultZone: http://${eureka.instance.hostname}:8761/eureka/logging:level:# log 级别org.springframework.cloud.gateway: debug---spring:# 配置文件名称,用来标识不同环境的配置。由 spring.profiles.active 的值来决定使用哪组配置。## 转发指定服务并传入参数profiles: route_addRequestParameterapplication:# 应用名称name: gateway-mastercloud:gateway:discovery:locator:# 是否和服务注册与发现组件结合,设置为 true 后可以直接使用应用名称调用服务enabled: true# 路由(routes:路由,它由唯一标识(ID)、目标服务地址(uri)、一组断言(predicates)和一组过滤器组成(filters)。filters 不是必需参数。)routes:# 路由标识(id:标识,具有唯一性) 转发指定服务并传入参数- id: route_addRequestParameter# 目标服务地址(uri:地址,请求转发后的地址)uri: lb://gateway-service# 路由条件(predicates:断言,匹配 HTTP 请求内容)predicates:## 匹配 GET 请求- Method=GET# 过滤器(filters:过滤器,过滤规则)filters:## 添加指定参数- AddRequestParameter=age, threeeureka:instance:# 使用 ip 代替实例名prefer-ip-address: true# 实例的主机名hostname: ${spring.cloud.client.ip-address}# 实例的 ID 规则instance-id: ${spring.cloud.client.ip-address}:${spring.application.name}:${server.port}client:serviceUrl:# 注册中心地址defaultZone: http://${eureka.instance.hostname}:8761/eureka/logging:level:# log 级别org.springframework.cloud.gateway: debug---spring:# 配置文件名称,用来标识不同环境的配置。由 spring.profiles.active 的值来决定使用哪组配置。## 熔断profiles: route_hystrixapplication:# 应用名称name: gateway-mastercloud:gateway:discovery:locator:# 是否和服务注册与发现组件结合,设置为 true 后可以直接使用应用名称调用服务enabled: true# 路由(routes:路由,它由唯一标识(ID)、目标服务地址(uri)、一组断言(predicates)和一组过滤器组成(filters)。filters 不是必需参数。)routes:# 路由标识(id:标识,具有唯一性) 熔断- id: route_hystrix# 目标服务地址(uri:地址,请求转发后的地址)uri: lb://gateway-service# 路由条件(predicates:断言,匹配 HTTP 请求内容)predicates:## 匹配 GET 请求- Method=GET# 过滤器(filters:过滤器,过滤规则)filters:## 添加指定参数- AddRequestParameter=age, three## 熔断- name: Hystrixargs:name: fallbackcmd### fallback 时调用的方法 http://localhost:8000/fallbackfallbackUri: forward:/fallbackeureka:instance:# 使用 ip 代替实例名prefer-ip-address: true# 实例的主机名hostname: ${spring.cloud.client.ip-address}# 实例的 ID 规则instance-id: ${spring.cloud.client.ip-address}:${spring.application.name}:${server.port}client:serviceUrl:# 注册中心地址defaultZone: http://${eureka.instance.hostname}:8761/eureka/logging:level:# log 级别org.springframework.cloud.gateway: debug---spring:# 配置文件名称,用来标识不同环境的配置。由 spring.profiles.active 的值来决定使用哪组配置。## 限流profiles: route_requestRateLimiterredis:host: localhostport: 6379database: 0application:# 应用名称name: gateway-mastercloud:gateway:discovery:locator:# 是否和服务注册与发现组件结合,设置为 true 后可以直接使用应用名称调用服务enabled: true# 路由(routes:路由,它由唯一标识(ID)、目标服务地址(uri)、一组断言(predicates)和一组过滤器组成(filters)。filters 不是必需参数。)routes:# 路由标识(id:标识,具有唯一性) 限流- id: route_requestRateLimiter# 目标服务地址(uri:地址,请求转发后的地址)uri: lb://gateway-service# 路由条件(predicates:断言,匹配 HTTP 请求内容)predicates:## 匹配 GET 请求- Method=GET# 过滤器(filters:过滤器,过滤规则)filters:## 添加指定参数- AddRequestParameter=age, three## 限流- name: RequestRateLimiterargs:### 限流过滤器的 Bean 名称key-resolver: '#{@uriKeyResolver}'### 希望允许用户每秒处理多少个请求redis-rate-limiter.replenishRate: 1### 用户允许在一秒钟内完成的最大请求数redis-rate-limiter.burstCapacity: 3eureka:instance:# 使用 ip 代替实例名prefer-ip-address: true# 实例的主机名hostname: ${spring.cloud.client.ip-address}# 实例的 ID 规则instance-id: ${spring.cloud.client.ip-address}:${spring.application.name}:${server.port}client:serviceUrl:# 注册中心地址defaultZone: http://${eureka.instance.hostname}:8761/eureka/logging:level:# log 级别org.springframework.cloud.gateway: debug---spring:# 配置文件名称,用来标识不同环境的配置。由 spring.profiles.active 的值来决定使用哪组配置。## 综合profiles: route_allredis:host: localhostport: 6379database: 0application:# 应用名称name: gateway-mastercloud:gateway:discovery:locator:# 是否和服务注册与发现组件结合,设置为 true 后可以直接使用应用名称调用服务enabled: true# 路由(routes:路由,它由唯一标识(ID)、目标服务地址(uri)、一组断言(predicates)和一组过滤器组成(filters)。filters 不是必需参数。)routes:# 路由标识(id:标识,具有唯一性) 综合- id: route_all# 目标服务地址(uri:地址,请求转发后的地址)uri: lb://gateway-service# 路由条件(predicates:断言,匹配 HTTP 请求内容)predicates:## 转发地址格式为 uri/routeAll,/all 部分会被下面的过滤器给截取掉- Path=/all/routeAll## 匹配 GET 请求- Method=GET# 过滤器(filters:过滤器,过滤规则)filters:## 截取路径位数- StripPrefix=1## 添加指定参数- AddRequestParameter=pass, yes## 熔断- name: Hystrixargs:name: fallbackcmd### fallback 时调用的方法 http://localhost:8000/fallbackfallbackUri: forward:/fallback## 限流- name: RequestRateLimiterargs:### 限流过滤器的 Bean 名称key-resolver: '#{@uriKeyResolver}'### 希望允许用户每秒处理多少个请求redis-rate-limiter.replenishRate: 1### 用户允许在一秒钟内完成的最大请求数redis-rate-limiter.burstCapacity: 3eureka:instance:# 使用 ip 代替实例名prefer-ip-address: true# 实例的主机名hostname: ${spring.cloud.client.ip-address}# 实例的 ID 规则instance-id: ${spring.cloud.client.ip-address}:${spring.application.name}:${server.port}client:serviceUrl:# 注册中心地址defaultZone: http://${eureka.instance.hostname}:8761/eureka/logging:level:# log 级别org.springframework.cloud.gateway: debug
注意配置注册中心地址的端口都为 8761 也就是上面注册中心工程配置的端口
每一对 ‘—’ 符号中的配置文件都是单独的,使用 spring.profiles.active 指定
每一对 ‘—’ 符号中的配置文件都只配置了一个 route(路由)
route(路由)由四部分组成,其中 filters 不是必须参数
唯一标识(ID)、目标服务地址(uri)、一组断言(predicates)和一组过滤器组成(filters)
master-service - 简单尝试
spring:# 配置文件名称,用来标识不同环境的配置。由 spring.profiles.active 的值来决定使用哪组配置。## 简单尝试profiles: route_simpleapplication:# 应用名称name: gateway-mastercloud:gateway:discovery:locator:# 是否和服务注册与发现组件结合,设置为 true 后可以直接使用应用名称调用服务enabled: true# 路由(routes:路由,它由唯一标识(ID)、目标服务地址(uri)、一组断言(predicates)和一组过滤器组成(filters)。filters 不是必需参数。)routes:# 路由标识(id:标识,具有唯一性) 简单尝试- id: route_simple# 目标服务地址(uri:地址,请求转发后的地址)uri: https://www.zouwencong.com# 路由条件(predicates:断言,匹配 HTTP 请求内容)predicates:## 转发地址格式为 uri/archive- Path=/archive
停止注册中心工程(registry-service)、服务工程 A 和服务工程 B
把 master-service - application.yml 配置文件中最上面的 spring.profiles.active 的值更改为 route_simple
上面配置文件内容意思是当访问 http://localhost:8000/archive (网关地址/archive)
会被转发到 https://www.zouwencong.com/archive/ (uri/archive)
启动注册中心工程(registry-service)和网关工程(master-service)
项目启动成功后访问:http://localhost:8000/archive
发现页面会自动被跳转到:https://www.zouwencong.com/archive/
证明服务转发成功
master-service - 截取请求
spring:#配置文件名称,用来标识不同环境的配置。由 spring.profiles.active 的值来决定使用哪组配置。##截取请求profiles: route_stripPrefixapplication:# 应用名称name: gateway-mastercloud:gateway:discovery:locator:# 是否和服务注册与发现组件结合,设置为 true 后可以直接使用应用名称调用服务enabled: true# 路由(routes:路由,它由唯一标识(ID)、目标服务地址(uri)、一组断言(predicates)和一组过滤器组成(filters)。filters 不是必需参数。)routes:# 路由标识(id:标识,具有唯一性) 截取请求- id: route_simple# 目标服务地址(uri:地址,请求转发后的地址)uri: https://www.zouwencong.com# 路由条件(predicates:断言,匹配 HTTP 请求内容)predicates:## 转发地址格式为 uri/archive,/str 部分会被下面的过滤器给截取掉- Path=/str/archivefilters:## 截取路径位数- StripPrefix=1eureka:instance:# 使用 ip 代替实例名prefer-ip-address: true# 实例的主机名hostname: ${spring.cloud.client.ip-address}# 实例的 ID 规则instance-id: ${spring.cloud.client.ip-address}:${spring.application.name}:${server.port}client:serviceUrl:# 注册中心地址defaultZone: http://${eureka.instance.hostname}:8761/eureka/logging:level:# log 级别org.springframework.cloud.gateway: debug
停止注册中心工程(registry-service)和网关工程(master-service)
把 master-service - application.yml 配置文件中最上面的 spring.profiles.active 的值更改为 route_stripPrefix
上面配置文件内容意思是访问的路径 http://localhost:8000/str/archive (网关地址/str/archive)截取 /str 部分,
截取后被转发到 https://www.zouwencong.com/archive/ (uri/archive)
启动注册中心工程(registry-service)和网关工程(master-service)
项目启动成功后访问:http://localhost:8000/str/archive
发现页面会自动被跳转到:https://www.zouwencong.com/archive/
证明路径被截取并服务转发成功
master-service - 转发指定地址并传入参数
spring:#配置文件名称,用来标识不同环境的配置。由 spring.profiles.active 的值来决定使用哪组配置。##转发指定地址并传入参数profiles: route_uriapplication:# 应用名称name: gateway-mastercloud:gateway:discovery:locator:# 是否和服务注册与发现组件结合,设置为 true 后可以直接使用应用名称调用服务enabled: true# 路由(routes:路由,它由唯一标识(ID)、目标服务地址(uri)、一组断言(predicates)和一组过滤器组成(filters)。filters 不是必需参数。)routes:# 路由标识(id:标识,具有唯一性) 转发指定地址并传入参数- id: route_uri# 目标服务地址(uri:地址,请求转发后的地址)uri: http://localhost:9000# 路由条件(predicates:断言,匹配 HTTP 请求内容)predicates:## 匹配 GET 请求- Method=GET# 过滤器(filters:过滤器,过滤规则)filters:## 添加指定参数- AddRequestParameter=name, zwceureka:instance:# 使用 ip 代替实例名prefer-ip-address: true# 实例的主机名hostname: ${spring.cloud.client.ip-address}# 实例的 ID 规则instance-id: ${spring.cloud.client.ip-address}:${spring.application.name}:${server.port}client:serviceUrl:# 注册中心地址defaultZone: http://${eureka.instance.hostname}:8761/eureka/logging:level:# log 级别org.springframework.cloud.gateway: debug
停止注册中心工程(registry-service)和网关工程(master-service)
把 master-service - application.yml 配置文件中最上面的 spring.profiles.active 的值更改为 route_uri
上面配置文件内容意思是访问的路径 http://localhost:8000/name (网关地址/name)
会被转发到 http://localhost:9000/name(uri/name),并传入 ‘name=zwc’ 参数(注意为 Get 请求)
启动注册中心工程(registry-service),网关工程(master-service)和服务工程 A(a-service)
项目启动成功后访问:http://localhost:8000/name
输出内容:‘My name is zwc. aaa’(通过网关转发 - 参数有值)
打开新页面访问:http://localhost:9000/name
输出内容:‘My name is null. aaa’(直接访问 - 参数没有值)
证明转发指定地址并传入参数成功
master-service - 转发指定服务并传入参数
spring:#配置文件名称,用来标识不同环境的配置。由 spring.profiles.active 的值来决定使用哪组配置。##转发指定服务并传入参数profiles: route_addRequestParameterapplication:# 应用名称name: gateway-mastercloud:gateway:discovery:locator:# 是否和服务注册与发现组件结合,设置为 true 后可以直接使用应用名称调用服务enabled: true# 路由(routes:路由,它由唯一标识(ID)、目标服务地址(uri)、一组断言(predicates)和一组过滤器组成(filters)。filters 不是必需参数。)routes:# 路由标识(id:标识,具有唯一性) 转发指定服务并传入参数- id: route_addRequestParameter# 目标服务地址(uri:地址,请求转发后的地址)uri: lb://gateway-service# 路由条件(predicates:断言,匹配 HTTP 请求内容)predicates:## 匹配 GET 请求- Method=GET# 过滤器(filters:过滤器,过滤规则)filters:## 添加指定参数- AddRequestParameter=age, threeeureka:instance:# 使用 ip 代替实例名prefer-ip-address: true# 实例的主机名hostname: ${spring.cloud.client.ip-address}# 实例的 ID 规则instance-id: ${spring.cloud.client.ip-address}:${spring.application.name}:${server.port}client:serviceUrl:# 注册中心地址defaultZone: http://${eureka.instance.hostname}:8761/eureka/logging:level:# log 级别org.springframework.cloud.gateway: debug
停止注册中心工程(registry-service),网关工程(master-service)和服务工程 A(a-service)
把 master-service - application.yml 配置文件中最上面的 spring.profiles.active 的值更改为 route_addRequestParameter
上面配置文件内容意思是访问的路径 http://localhost:8000/age (网关地址/age)会被转发到 http://gateway-service/age(uri/age),并传入 ‘age=three’ 参数(注意为 Get 请求)
注意此处的配置 uri: lb://gateway-service 与之前都有所不同,之前都是指定了明确的转发地址,可以满足单个服务转发的需求,但是一般情况都会有多个服务,所以这里是指定的服务名称,格式为:lb://应用注册服务名。
启动注册中心工程(registry-service),网关工程(master-service)和服务工程 A/B(a-service、b-service)
项目启动成功后访问:http://localhost:8000/age
这时可能会报错 500.错误信息为 ‘Unable to find instance for gateway-service’
这种情况不要慌张,只是服务还没有被注册到注册中心,稍等片刻再访问
多次访问:http://localhost:8000/age
轮流输出内容:‘I am three years old this year. aaa’ 和 ‘I am three years old this year. bbb’
此时还通过网关达到了负载均衡的效果
证明转发指定服务并传入参数成功
master-service - 熔断
spring:#配置文件名称,用来标识不同环境的配置。由 spring.profiles.active 的值来决定使用哪组配置。##熔断profiles: route_hystrixapplication:# 应用名称name: gateway-mastercloud:gateway:discovery:locator:# 是否和服务注册与发现组件结合,设置为 true 后可以直接使用应用名称调用服务enabled: true# 路由(routes:路由,它由唯一标识(ID)、目标服务地址(uri)、一组断言(predicates)和一组过滤器组成(filters)。filters 不是必需参数。)routes:# 路由标识(id:标识,具有唯一性) 熔断- id: route_hystrix# 目标服务地址(uri:地址,请求转发后的地址)uri: lb://gateway-service# 路由条件(predicates:断言,匹配 HTTP 请求内容)predicates:## 匹配 GET 请求- Method=GET# 过滤器(filters:过滤器,过滤规则)filters:## 添加指定参数- AddRequestParameter=age, three## 熔断- name: Hystrixargs:name: fallbackcmd### fallback 时调用的方法 http://localhost:8000/fallbackfallbackUri: forward:/fallbackeureka:instance:# 使用 ip 代替实例名prefer-ip-address: true# 实例的主机名hostname: ${spring.cloud.client.ip-address}# 实例的 ID 规则instance-id: ${spring.cloud.client.ip-address}:${spring.application.name}:${server.port}client:serviceUrl:# 注册中心地址defaultZone: http://${eureka.instance.hostname}:8761/eureka/logging:level:# log 级别org.springframework.cloud.gateway: debug
停止注册中心工程(registry-service),网关工程(master-service)和服务工程 A/B(a-service、b-service)
把 master-service - application.yml 配置文件中最上面的 spring.profiles.active 的值更改为 route_hystrix
上面配置文件内容意思是访问的路径 http://localhost:8000/age (网关地址/age)会被转发到 http://gateway-service/age(uri/age),并传入 ‘age=three’ 参数(注意为 Get 请求)
注意此处的配置 uri: lb://gateway-service 与之前都有所不同,之前都是指定了明确的转发地址,可以满足单个服务转发的需求,但是一般情况都会有多个服务,所以这里是指定的服务名称,格式为:lb://应用注册服务名。
此处还多配置了一个过滤器 ‘- name: Hystrix’(熔断)
当请求服务出错时,会调用 fallback,路径为:http://localhost:8000/fallback (网关地址/fallback)
此时就需要如下前端控制器
master-service - 熔断 - controller
package com.zwc.gateway.hystrix;import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;/*** @ClassName FallbackController* @Desc TODO 网关断路器* @Date 2019/6/23 19:33* @Version 1.0*/
@RestController
public class FallbackController {/** @ClassName FallbackController* @Desc TODO 网关断路器* @Date 2019/6/23 19:35* @Version 1.0*/@RequestMapping("/fallback")public String fallback() {return "I'm Spring Cloud Gateway fallback.";}
}
8. 启动注册中心工程(registry-service),网关工程(master-service)和服务工程 A/B(a-service、b-service)
项目启动成功后访问:http://localhost:8000/age
输出内容:‘I’m Spring Cloud Gateway fallback.’
证明熔断成功
master-service - 限流(重点,解决不生效问题)
spring:#配置文件名称,用来标识不同环境的配置。由 spring.profiles.active 的值来决定使用哪组配置。##限流profiles: route_requestRateLimiterredis:host: localhostport: 6379database: 0application:# 应用名称name: gateway-mastercloud:gateway:discovery:locator:# 是否和服务注册与发现组件结合,设置为 true 后可以直接使用应用名称调用服务enabled: true# 路由(routes:路由,它由唯一标识(ID)、目标服务地址(uri)、一组断言(predicates)和一组过滤器组成(filters)。filters 不是必需参数。)routes:# 路由标识(id:标识,具有唯一性) 限流- id: route_requestRateLimiter# 目标服务地址(uri:地址,请求转发后的地址)uri: lb://gateway-service# 路由条件(predicates:断言,匹配 HTTP 请求内容)predicates:## 匹配 GET 请求- Method=GET# 过滤器(filters:过滤器,过滤规则)filters:## 添加指定参数- AddRequestParameter=age, three## 限流- name: RequestRateLimiterargs:### 限流过滤器的 Bean 名称key-resolver: '#{@uriKeyResolver}'### 希望允许用户每秒处理多少个请求redis-rate-limiter.replenishRate: 1### 用户允许在一秒钟内完成的最大请求数redis-rate-limiter.burstCapacity: 3eureka:instance:# 使用 ip 代替实例名prefer-ip-address: true# 实例的主机名hostname: ${spring.cloud.client.ip-address}# 实例的 ID 规则instance-id: ${spring.cloud.client.ip-address}:${spring.application.name}:${server.port}client:serviceUrl:# 注册中心地址defaultZone: http://${eureka.instance.hostname}:8761/eureka/logging:level:# log 级别org.springframework.cloud.gateway: debug
停止注册中心工程(registry-service),网关工程(master-service)和服务工程 A/B(a-service、b-service)
把 master-service - application.yml 配置文件中最上面的 spring.profiles.active 的值更改route_requestRateLimiter
上面配置文件内容意思是访问的路径 http://localhost:8000/age (网关地址/age)会被转发到 http://gateway-service/age(uri/age),并传入 ‘age=three’ 参数(注意为 Get 请求)
注意此处还需要配置 redis 的连接信息
注意此处是结合 redis 实现的限流,所以 filter 过滤器的 name 必须为 RequestRateLimiter
并且通过实现 KeyResolver 类来自定义限流策略,如下
master-service - 限流 - 策略
package com.zwc.gateway.config.filters;import org.springframework.cloud.gateway.filter.ratelimit.KeyResolver;
import org.springframework.web.server.ServerWebExchange;
import reactor.core.publisher.Mono;/*** @ClassName UriKeyResolver* @Desc TODO Spring Cloud Gateway 网关限流过滤器* @Date 2019/6/23 17:59* @Version 1.0*/
public class UriKeyResolver implements KeyResolver {/** @ClassName UriKeyResolver* @Desc TODO 根据请求的 uri 限流* @Date 2019/6/29 17:25* @Version 1.0*/@Overridepublic Mono<String> resolve(ServerWebExchange exchange) {return Mono.just(exchange.getRequest().getURI().getPath());}}
启动本地 redis(redis-server.exe) 服务
启动注册中心工程(registry-service),网关工程(master-service)和服务工程 A/B(a-service、b-service)
项目启动成功后访问:http://localhost:8000/age
此时限流却无论如何都不生效,原因有如下两点
① redis-server 版本过低!我 Windows 本地是 redis-2.4.2 版本的,要用 3 以上的版本!!!
② 数据在 redis 中存储的时间只有几秒,所以得使用 monitor 指令来动态的观察!!!
打开 redis-cli.exe,输入命令 monitor
快速刷新地址:http://localhost:8000/age
页面上会出现 429,redis-cli.exe 中会出现很多数据交互(request_rate_limiter.xxx 开头的 key)
证明限流成功
master-service - 综合
spring:#配置文件名称,用来标识不同环境的配置。由 spring.profiles.active 的值来决定使用哪组配置。##综合profiles: route_allredis:host: localhostport: 6379database: 0application:# 应用名称name: gateway-mastercloud:gateway:discovery:locator:# 是否和服务注册与发现组件结合,设置为 true 后可以直接使用应用名称调用服务enabled: true# 路由(routes:路由,它由唯一标识(ID)、目标服务地址(uri)、一组断言(predicates)和一组过滤器组成(filters)。filters 不是必需参数。)routes:# 路由标识(id:标识,具有唯一性) 综合- id: route_all# 目标服务地址(uri:地址,请求转发后的地址)uri: lb://gateway-service# 路由条件(predicates:断言,匹配 HTTP 请求内容)predicates:## 转发地址格式为 uri/routeAll,/all 部分会被下面的过滤器给截取掉- Path=/all/routeAll## 匹配 GET 请求- Method=GET# 过滤器(filters:过滤器,过滤规则)filters:## 截取路径位数- StripPrefix=1## 添加指定参数- AddRequestParameter=pass, yes## 熔断- name: Hystrixargs:name: fallbackcmd### fallback 时调用的方法 http://localhost:8000/fallbackfallbackUri: forward:/fallback## 限流- name: RequestRateLimiterargs:### 限流过滤器的 Bean 名称key-resolver: '#{@uriKeyResolver}'### 希望允许用户每秒处理多少个请求redis-rate-limiter.replenishRate: 1### 用户允许在一秒钟内完成的最大请求数redis-rate-limiter.burstCapacity: 3eureka:instance:# 使用 ip 代替实例名prefer-ip-address: true# 实例的主机名hostname: ${spring.cloud.client.ip-address}# 实例的 ID 规则instance-id: ${spring.cloud.client.ip-address}:${spring.application.name}:${server.port}client:serviceUrl:# 注册中心地址defaultZone: http://${eureka.instance.hostname}:8761/eureka/logging:level:# log 级别org.springframework.cloud.gateway: debug
停止注册中心工程(registry-service),网关工程(master-service)和服务工程 A/B(a-service、b-service)
把 master-service - application.yml 配置文件中最上面的 spring.profiles.active 的值更改为 route_all
上面配置文件内容意思是访问的路径 http://localhost:8000/all/routeAll (网关地址/all/routeAll)截取 /all 部分,会被转发到 http://gateway-service/routeAll(uri/routeAll),并传入 ‘pass=yes’ 参数(注意为 Get 请求)
启动注册中心工程(registry-service),网关工程(master-service)和服务工程 A/B(a-service、b-service)
项目启动成功后访问:http://localhost:8000/all/routeAll
首先会返回 ‘I’m Spring Cloud Gateway fallback.’,因为服务还未被注册到注册中心
然后会返回 ‘{“msg”:“缺少凭证”,“code”:-1}’,因为配置了全局过滤器,如下
package com.zwc.gateway.config.filters;import com.alibaba.fastjson.JSONObject;
import org.springframework.cloud.gateway.filter.GatewayFilterChain;
import org.springframework.cloud.gateway.filter.GlobalFilter;
import org.springframework.core.Ordered;
import org.springframework.http.HttpStatus;
import org.springframework.http.server.reactive.ServerHttpRequest;
import org.springframework.http.server.reactive.ServerHttpResponse;
import org.springframework.web.server.ServerWebExchange;
import reactor.core.publisher.Mono;
import org.springframework.core.io.buffer.DataBuffer;import java.net.InetSocketAddress;
import java.nio.charset.StandardCharsets;/*** @ClassName TokenFilter* @Desc TODO 请求认证过滤器* @Date 2019/6/29 17:49* @Version 1.0*/
public class TokenFilter implements GlobalFilter{@Overridepublic Mono<Void> filter(ServerWebExchange exchange, GatewayFilterChain chain) {// 请求对象ServerHttpRequest request = exchange.getRequest();// 响应对象ServerHttpResponse response = exchange.getResponse();// 只有综合路由才添加这个全局过滤器(routesId:route_all)// 如果请求路径中不存在 routeAll 字符串if(request.getURI().toString().indexOf("routeAll") == -1){System.out.println("filter -> return");// 直接跳出return chain.filter(exchange);}// 从请求中获取 token 参数String token = exchange.getRequest().getQueryParams().getFirst("token");// 如果为空,那么将返回 401if (token == null || token.isEmpty()) {// 响应消息内容对象JSONObject message = new JSONObject();// 响应状态message.put("code", -1);// 响应内容message.put("msg", "缺少凭证");// 转换响应消息内容对象为字节byte[] bits = message.toJSONString().getBytes(StandardCharsets.UTF_8);DataBuffer buffer = response.bufferFactory().wrap(bits);// 设置响应对象状态码 401response.setStatusCode(HttpStatus.UNAUTHORIZED);// 设置响应对象内容并且指定编码,否则在浏览器中会中文乱码response.getHeaders().add("Content-Type", "text/plain;charset=UTF-8");// 返回响应对象return response.writeWith(Mono.just(buffer));}// 获取请求地址String beforePath = request.getPath().pathWithinApplication().value();// 获取响应状态码HttpStatus beforeStatusCode = response.getStatusCode();System.out.println("响应码:" + beforeStatusCode + ",请求路径:" + beforePath);// 请求前System.out.println("filter -> before");// 如果不为空,就通过return chain.filter(exchange).then(Mono.fromRunnable(() -> {// 获取请求地址String afterPath = request.getPath().pathWithinApplication().value();// 获取响应状态码HttpStatus afterStatusCode = response.getStatusCode();System.out.println("响应码:" + afterStatusCode + ",请求路径:" + afterPath);// 响应后System.out.println("filter -> after");}));}}
全局过滤器,不需要配置在配置文件中,作用于所有路由;只是这里在处理前做了判断,只有路径中存在routeAll 字符串才到后续处理;并且处理分为请求前的处理,和响应后的处理
此时在地址:http://localhost:8000/all/routeAll 中添加 token 参数
访问:http://localhost:8000/all/routeAll?token=123
轮流输出内容:‘Can I pass? yes! port:9000’ 和 ‘Can I pass? yes! port:9001’
观察 gateway 工程的控制台,会有如下内容输出
响应码:null,请求路径:/routeAll
filter -> before
响应码:200,请求路径:/routeAll
filter -> after13. 证明全局过滤器过滤成功
service 工程 - 项目结构
把多工程项目使用 IntelliJ IDEA 打开
1.把项目从 GitHub 中下载到你的本地
2.打开 IntelliJ IDEA
3.点击 File -> Open
4.打开你下载到本地的项目目录
5.springcloud-gateway -> springcloud-gateway-service(选择打开此工程)
6.打开 service 工程后
7.再次点击 File -> Project Structrue
8.选择 Modules,点击 ‘+’ 符号
9.点击 Import Module
10.还是打开你下载到本地的项目目录
11.springcloud-gateway -> springcloud-gateway-commons -> pom.xml
12.点击 OK
13.点击 Next,Finish
14.点击 Apply,OK
最后![](/assets/blank.gif)
全套的Java面试宝典手册:性能调优+微服务架构+并发编程+开源框架+分布式”等七大面试专栏,包含Tomcat、JVM、MySQL、SpringCloud、SpringBoot、Dubbo、并发、Spring、SpringMVC、MyBatis、Zookeeper、Ngnix、Kafka、MQ、Redis、MongoDB、memcached等等。
有需要的朋友可以关注公众号【程序媛小琬】即可获取。
熬夜肝了这篇Spring Cloud Gateway的功能及综合使用相关推荐
- Spring Cloud Gateway之Predict篇
Spring Cloud gateway工作流程 在之前的文章的Spring Cloud GateWay初体验中,大家已经对Spring Cloud Gateway的功能有一个初步的认识,网关作为一个 ...
- Spring Cloud Gateway 之Predict篇
转载请标明出处: http://blog.csdn.net/forezp/article/details/84926662 本文出自方志朋的博客 个人博客纯净版:https://www.fangzhi ...
- 跟我学SpringCloud | 第十二篇:Spring Cloud Gateway初探
SpringCloud系列教程 | 第十二篇:Spring Cloud Gateway初探 Springboot: 2.1.6.RELEASE SpringCloud: Greenwich.SR1 如 ...
- 第五章 微服务网关Spring Cloud Gateway
5.1 微服务网关简介 第三章我们介绍了通过Spring Cloud LoadBalancer实现了微服务之间的调⽤和负载均衡,以及使⽤Spring Cloud OpenFeign声明式调⽤,那我们的 ...
- spring cloud gateway之filter篇
点击上方"方志朋",选择"置顶或者星标" 你的关注意义重大! 在上一篇文章详细的介绍了Gateway的Predict,Predict决定了请求由哪一个路由处理, ...
- 实战 Spring Cloud Gateway 之限流篇
来源:https://www.aneasystone.com/archives/2020/08/spring-cloud-gateway-current-limiting.html 话说在 Sprin ...
- java版电子商务spring cloud分布式微服务b2b2c社交电商-spring cloud gateway之filter篇
社交电商平台源码请加企鹅求求:一零三八七七四六二六.filter的作用和生命周期 由filter工作流程点,可以知道filter有着非常重要的作用,在"pre"类型的过滤器可以做参 ...
- 【Spring Cloud Alibaba 实战 | 总结篇】Spring Cloud Gateway + Spring Security OAuth2 + JWT 实现微服务统一认证授权和鉴权
一. 前言 hi,大家好~ 好久没更文了,期间主要致力于项目的功能升级和问题修复中,经过一年时间这里只贴出关键部分代码的打磨,[有来]终于迎来v2.0版本,相较于v1.x版本主要完善了OAuth2认证 ...
- 【云原生微服务>SCG网关篇十二】Spring Cloud Gateway集成Sentinel API实现多种限流方式
文章目录 一.前言 二.Gateway集成Sentinel API 0.集成Sentinel的核心概念 1)GatewayFlowRule 和 ApiDefinition 2)GatewayFlowR ...
最新文章
- 2020年人工智能汽车将出台多项标准
- Doxygen简单经验谈。。。
- python使用matplotlib可视化线图(line plot)、使用arrow函数在matplotlib可视化图像中添加箭头(drawing arrows in matplotlib)
- Linux_文件系统磁盘分区
- C#二进制格式与文件相互转换
- Qt Creator用户互动方法
- 圆章能随便刻吗_当归、人参、虫草熬成的养生汤,能随便销售吗?
- Metamask + remix:在ropsten测试链上取出已经部署的合约并进行一些操作
- JS + HTml 时钟代码实现
- Kali下安装Wiznote
- 零基础入门微信小程序开发
- 关于清除丢失贴图与IES文件
- Flink Window TOPN: The window can only be ordered in ASCENDING mode.
- android OpenGL渲染带骨骼动画的3D模型
- 神级 IDEA 插件,能让你的代码飞起来!
- Ext cookies设置、获取和清除
- Python-illegal multibyte sequence
- php dingo和jwt,三、Laravel5.4+Dingo+JWT 开发API
- 关于Excel表格导出方法--application/vnd.ms-excel
- iOS登陆密码加密-HMAC