Sentinel限流的使用方法
发表于:2026-11-01 作者:千家信息网编辑
千家信息网最后更新 2026年11月01日,这篇文章主要讲解了"Sentinel限流的使用方法",文中的讲解内容简单清晰,易于学习与理解,下面请大家跟着小编的思路慢慢深入,一起来研究和学习"Sentinel限流的使用方法"吧!Sentinel
千家信息网最后更新 2026年11月01日Sentinel限流的使用方法
这篇文章主要讲解了"Sentinel限流的使用方法",文中的讲解内容简单清晰,易于学习与理解,下面请大家跟着小编的思路慢慢深入,一起来研究和学习"Sentinel限流的使用方法"吧!
Sentinel 系列教程-使用Sentinel限流
前言: Sentinel 是由alibaba出品的,针对于系统负载保护的组件,其有丰富的流量防护手段和多样化的流量整型策略而被广大使用。 以下是转自Sentinel官方的介绍: 随着微服务的流行,服务和服务之间的稳定性变得越来越重要。Sentinel 是面向分布式服务架构的轻量级流量控制组件,主要以流量为切入点,从限流、流量整形、熔断降级、系统负载保护等多个维度来帮助您保障微服务的稳定性。 Sentinel-wiki Sentinel GitHub wiki 有兴趣的童鞋可以去了解。
本文以Sentinel 1.6.3 为例;
引入sentinel-core
com.alibaba.csp sentinel-core 1.6.3
加载规则信息
private static final String RESOURCE_NAME = "hello";/** * 加载限流规则 */public static void loadRules(){ List rules = new ArrayList(); FlowRule flowRule = new FlowRule(); flowRule.setResource(RESOURCE_NAME); //资源名 flowRule.setLimitApp("default");//default 代表对所有应用生效 flowRule.setGrade(RuleConstant.FLOW_GRADE_QPS); //限流阈值类型 flowRule.setCount(10); //阈值 rules.add(flowRule); FlowRuleManager.loadRules(rules);} 添加资源入口处理限流异常
/** * 执行方法 * @param hello */public static void hello(String hello){ Entry entry = null; try { entry = SphU.entry(RESOURCE_NAME); log.info("args hello value is {}",hello); }catch (Exception e){ if(FlowException.isBlockException(e)){ log.error("block resourceName: {}",RESOURCE_NAME); } }finally { if(entry !=null){ entry.exit(); } }}模拟调用测试
public static void main(String[] args) { loadRules(); for(int i=0;i<20;i++){ hello("hello"+i); }}运行记录
15:26:08.453 [main] INFO com.example.sentinel.sentineldemo.SampleFlowDemo - args hello value is hello015:26:08.458 [main] INFO com.example.sentinel.sentineldemo.SampleFlowDemo - args hello value is hello115:26:08.458 [main] INFO com.example.sentinel.sentineldemo.SampleFlowDemo - args hello value is hello215:26:08.458 [main] INFO com.example.sentinel.sentineldemo.SampleFlowDemo - args hello value is hello315:26:08.459 [main] INFO com.example.sentinel.sentineldemo.SampleFlowDemo - args hello value is hello415:26:08.459 [main] INFO com.example.sentinel.sentineldemo.SampleFlowDemo - args hello value is hello515:26:08.459 [main] INFO com.example.sentinel.sentineldemo.SampleFlowDemo - args hello value is hello615:26:08.459 [main] INFO com.example.sentinel.sentineldemo.SampleFlowDemo - args hello value is hello715:26:08.459 [main] INFO com.example.sentinel.sentineldemo.SampleFlowDemo - args hello value is hello815:26:08.459 [main] INFO com.example.sentinel.sentineldemo.SampleFlowDemo - args hello value is hello915:26:08.492 [main] ERROR com.example.sentinel.sentineldemo.SampleFlowDemo - block resourceName: hello15:26:08.492 [main] ERROR com.example.sentinel.sentineldemo.SampleFlowDemo - block resourceName: hello15:26:08.493 [main] ERROR com.example.sentinel.sentineldemo.SampleFlowDemo - block resourceName: hello15:26:08.493 [main] ERROR com.example.sentinel.sentineldemo.SampleFlowDemo - block resourceName: hello15:26:08.493 [main] ERROR com.example.sentinel.sentineldemo.SampleFlowDemo - block resourceName: hello15:26:08.493 [main] ERROR com.example.sentinel.sentineldemo.SampleFlowDemo - block resourceName: hello15:26:08.493 [main] ERROR com.example.sentinel.sentineldemo.SampleFlowDemo - block resourceName: hello15:26:08.493 [main] ERROR com.example.sentinel.sentineldemo.SampleFlowDemo - block resourceName: hello15:26:08.493 [main] ERROR com.example.sentinel.sentineldemo.SampleFlowDemo - block resourceName: hello15:26:08.494 [main] ERROR com.example.sentinel.sentineldemo.SampleFlowDemo - block resourceName: hello
感谢各位的阅读,以上就是"Sentinel限流的使用方法"的内容了,经过本文的学习后,相信大家对Sentinel限流的使用方法这一问题有了更深刻的体会,具体使用情况还需要大家实践验证。这里是,小编将为大家推送更多相关知识点的文章,欢迎关注!
方法
流量
服务
使用方法
学习
内容
稳定性
系统
组件
规则
资源
阈值
保护
重要
之间
代表
入口
兴趣
分布式
切入点
数据库的安全要保护哪些东西
数据库安全各自的含义是什么
生产安全数据库录入
数据库的安全性及管理
数据库安全策略包含哪些
海淀数据库安全审计系统
建立农村房屋安全信息数据库
易用的数据库客户端支持安全管理
连接数据库失败ssl安全错误
数据库的锁怎样保障安全
上海喔噻互联网科技有限公司
江苏根荣互联网科技
互联网科技集团
奇酷互联网科技
万达互联网科技
火传媒上海互联网科技
衡水科技产业互联网平台
华脉科技工业互联网产品
太原新华互联网科技学校怎么样
恒银科技与互联网金融
重庆威客帮互联网科技
互联网科技公司实习生
花神(南京)互联网科技有限公司
如何创新互联网科技
科技互联网海报
杭州披云加互联网科技有限公司
互联网领先科技宣传片
有人说阿里系是互联网科技企业
35岁以上互联网科技行业
利用互联网等科技手段
互联网科技公司经营范围
互联网科技logo
欧洲十大科技互联网公司
互联网公司科技股
河南猎农互联网科技有限公司
互联网与医疗科技
互联网科技扶贫时间
河南住房之家互联网科技
浙南科技城互联网大厦招聘
科技互联网企业在行动