Gateway配合sentinel自定义限流_Gateway结合Sentinel1.8限流熔断管理以及自定义异常

本文详细介绍了如何将Spring Cloud Gateway与Sentinel 1.8集成,讲解了GatewayFlowRule、熔断降级策略,包括慢调用比例、异常比例和异常数,并指出Sentinel Dashboard的源码bug。同时,提供了配置Sentinel和启动参数的注意事项。
摘要由CSDN通过智能技术生成

6c6af621f7089af0d01c6ea8767153fa.gif

前言

之前老顾介绍了gateway集合sentinel1.8的整体概念介绍,今天老顾就来介绍一下,gateway如何与sentinel相结合,sentinel1.8降级规则的变化,以及dashboard源码的bug。

POM依赖

我们先创建一个gateway项目,要与Sentinel结合需要依赖一下jar包。

说明一下老顾把以前文章中的案例依赖的jar包进行了升级,针对SpringCloud Alibaba的版本需要升级到2.2.3.RELEASE版本;spring boot也升级到了2.3.3.RELEASE;spring cloud升级到Hoxton.SR8

<dependency>  <groupId>com.alibaba.cloudgroupId>  <artifactId>spring-cloud-starter-alibaba-sentinelartifactId>dependency>    <dependency>      <groupId>com.alibaba.cloudgroupId>      <artifactId>spring-cloud-alibaba-sentinel-gatewayartifactId>  dependency>        <dependency>    <groupId>com.alibaba.cspgroupId>  <artifactId>sentinel-spring-cloud-gateway-adapterartifactId>dependency>

不要搞错了哦,网上有些资料有坑

配置

网关项目中增加一个配置类,我们需要添加一个SentinelGatewayFilterSentinelGatewayBlockExceptionHandler实例

4b081df36f80580aa37b744047b7fe5d.png下载并安装sentinel-dashboard

之前老顾的文章已经介绍过了

1、下载地址:https://github.com/alibaba/Sentinel/releases根据自己需要下载对应版本,这里以sentinel-dashboard-1.8.0.jar为例

2、上传控制台jar包至linux服务器,启动sentinel控制台命(端口被占用请修改端口):

nohup java -Dserver.port=8081 -Dcsp.sentinel.dashboard.server=localhost:8081 -Dproject.name=sentinel-dashboard -jar sentinel-dashboard-1.8.0.jar &

3、访问后台:http://localhost:8081,用户名、密码默认都为:sentinel,也可在启动命令中自行配置 

1ae78a9fbe0c5c9934284c2f94c21dc7.png网关启动参数

为网关增加JVM启动参数

-Dcsp.sentinel.dashboard.server=localhost:8081

-Dproject.name=qy-tribe-gateway

-Dcsp.sentinel.api.port=8719

-Dcsp.sentinel.app.type=1

参数说明: -Dcsp.sentinel.dashboard.server:指定控制台地址和端口

-Dproject.name:在sentinel控制台中展示的项目名称

-Dcsp.sentinel.api.port:指定客户端监控 API 的端口(

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值