Spring-Cloud-Gateway集成Sentinel限流

1)gateway添加sentinel相关依赖

xml 复制代码
<spring-cloud.version>2021.0.1</spring-cloud.version>
<spring-cloud-alibaba.version>2021.0.1.0</spring-cloud-alibaba.version>

<dependencies>

    <!--gateway-->
    <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-starter-gateway</artifactId>
    </dependency>

    <!--sentinel-->
    <dependency>
        <groupId>com.alibaba.cloud</groupId>
        <artifactId>spring-cloud-starter-alibaba-sentinel</artifactId>
        <version>2021.0.1.0</version>
    </dependency>
    <!--sentinel-gateway-->
    <dependency>
        <groupId>com.alibaba.cloud</groupId>
        <artifactId>spring-cloud-alibaba-sentinel-gateway</artifactId>
        <version>2021.0.1.0</version>
    </dependency>

</dependencies>

2)gateway添加相关的配置

yml 复制代码
spring:
  cloud:
    gateway:
      routes:
        - id: user-service
          uri: http://localhost:8081
          predicates:
            - Path=/user/*
    sentinel:
      transport:
        dashboard: localhost:8888

3)启动gateway

4)下载sentinel控制台并启动

下载地址:https://github.com/alibaba/Sentinel/releases

启动:java -Dserver.port=8888 -jar sentinel-dashboard-1.8.6.jar

5)sentinel控制台添加流控规则

先访问一下网关:http://localhost:8080/user/1

添加流控规则:

6)jmeter压测

10个并发请求,只有5个会成功:

7)API分组限流

新建API分组

添加流控规则

测试代码下载:
https://github.com/xjs1919/enumdemo/tree/master/gateway-sentinel-demo

相关推荐
追风赶月、10 小时前
【Redis】哨兵(Sentinel)机制
数据库·redis·sentinel
泽济天下11 小时前
【工作记录】Kong Gateway入门篇之简介
gateway·kong
SHUIPING_YANG13 小时前
Nginx 返回 504 状态码表示 网关超时(Gateway Timeout)原因排查
运维·nginx·gateway
Volunteer Technology2 天前
SpringCloud Gateway知识点整理和全局过滤器实现
spring·spring cloud·gateway
matrixlzp2 天前
K8S Gateway AB测试、蓝绿发布、金丝雀(灰度)发布
kubernetes·gateway·ab测试
泽济天下3 天前
【工作记录】Kong Gateway 入门篇之部署及简单测试
gateway·kong
JAVA坚守者4 天前
API 网关核心功能解析:负载均衡、容灾、削峰降级原理与实战摘要
gateway·负载均衡·微服务架构·容灾备份·api 网关·削峰降级·云原生技术
大G哥5 天前
实战演练:用 AWS Lambda 和 API Gateway 构建你的第一个 Serverless API
云原生·serverless·云计算·gateway·aws
RingWu5 天前
微服务架构-限流、熔断:Alibaba Sentinel入门
微服务·架构·sentinel
说淑人6 天前
Spring Cloud & 以Gateway实现限流(自定义返回内容)
java·spring cloud·gateway·限流