0
点赞
收藏
分享

微信扫一扫

SpringCloudAlibaba网关Gateway集成Sentinel

上一篇:SpringCloudAlibaba集成Gateway动态路由Nacos服务

之前我们搭建了网关项目gateway-web,进行api管理。
我们之前使用Sentinel对web项目的接口和Dubbo 的RPC接口分别进行了流控,那么Sentinel能对网关项目进行流控吗,答案是肯定的。
Sentinel的GitHub中对适配Gateway做了介绍和demo,传送门:https://github.com/alibaba/Sentinel/wiki/%E4%B8%BB%E6%B5%81%E6%A1%86%E6%9E%B6%E7%9A%84%E9%80%82%E9%85%8D#api-gateway-%E9%80%82%E9%85%8D

但是这个文档已经比较老, 可以看到wiki是2年前编写的,由于我们现在用的SpringCloud和SpringBoot依赖是最新的,所以官方文档中的使用方式并不太适用。

下面来介绍一下,最新的使用方式。

pom.xml中引入依赖

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

application.yml文件中添加配置

spring:
application:
name: gateway-web
cloud:
sentinel:
transport:
dashboard: 127.0.0.1:8888
port: 8888

启动gateway-web项目,访问gateway-web接口:


可以在Sentinel管理后台发现gateway-web服务


对admin-1添加流控规则,设置qps为1:


疯狂访问gateway-web接口,出现错误信息:


打完收工。

举报

相关推荐

0 条评论