<em>Mac</em>Book项目 2009年学校开始实施<em>Mac</em>Book项目,所有师生配备一本<em>Mac</em>Book,并同步更新了校园无线网络。学校每周进行电脑技术更新,每月发送技术支持资料,极大改变了教学及学习方式。因此2011
2021-06-01 09:32:01
spring cloud基於http進行服務呼叫,大致過程如下:
<!-- 服務註冊與發現 --> <dependency> <groupId>com.alibaba.cloud</groupId> <artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId> </dependency> <!-- sentinel限流 --> <dependency> <groupId>com.alibaba.cloud</groupId> <artifactId>spring-cloud-starter-alibaba-sentinel</artifactId> </dependency>
為簡化處理,直接對url介面進行限流,不做服務呼叫
application.yml
spring: application: name: hello-sentinel cloud: nacos: discovery: server-addr: localhost:8848 sentinel: transport: dashboard: localhost:8081
限流可使用本地設定、或者sentinel dashboard設定
HelloController
@RestController public class HelloController { @SentinelResource(value = "hello", blockHandler = "blockHandle") @RequestMapping("/hello") public String hello(){ return "hello"; } public String blockHandle(BlockException e){ e.printStackTrace(); return "被限流了"; }
************
本地限流設定
CustomFlowRule
public class CustomFlowRule implements InitFunc { @Override public void init() throws Exception { List<FlowRule> flowRules = new ArrayList<>(); FlowRule flowRule = new FlowRule(); flowRule.setResource("hello"); flowRule.setCount(1); flowRule.setControlBehavior(RuleConstant.CONTROL_BEHAVIOR_DEFAULT); flowRules.add(flowRule); FlowRuleManager.loadRules(flowRules); } }
META-INF/services/com.alibaba.csp.sentinel.init.InitFunc
com.example.demo.rule.CustomFlowRule
jmeter 測試
2022-03-27 22:30:50.534 INFO 1791 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port(s): 8080 (http) with context path '' 2022-03-27 22:30:50.547 INFO 1791 --- [ main] c.a.c.n.registry.NacosServiceRegistry : nacos registry, DEFAULT_GROUP hello-sentinel 192.168.5.11:8080 register finished 2022-03-27 22:30:50.557 INFO 1791 --- [ main] com.example.demo.DemoApplication : Started DemoApplication in 2.227 seconds (JVM running for 2.824) 2022-03-27 22:31:04.044 INFO 1791 --- [nio-8080-exec-1] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring DispatcherServlet 'dispatcherServlet' 2022-03-27 22:31:04.044 INFO 1791 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet : Initializing Servlet 'dispatcherServlet' 2022-03-27 22:31:04.049 INFO 1791 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet : Completed initialization in 5 ms INFO: Sentinel log output type is: file INFO: Sentinel log charset is: utf-8 INFO: Sentinel log base directory is: /Users/huli/logs/csp/ INFO: Sentinel log name use pid is: false com.alibaba.csp.sentinel.slots.block.flow.FlowException com.alibaba.csp.sentinel.slots.block.flow.FlowException com.alibaba.csp.sentinel.slots.block.flow.FlowException com.alibaba.csp.sentinel.slots.block.flow.FlowException com.alibaba.csp.sentinel.slots.block.flow.FlowException com.alibaba.csp.sentinel.slots.block.flow.FlowException com.alibaba.csp.sentinel.slots.block.flow.FlowException com.alibaba.csp.sentinel.slots.block.flow.FlowException com.alibaba.csp.sentinel.slots.block.flow.FlowException
************
sentinel dashboard設定限流
啟動sentinel dashboard
java -Dserver.port=8081 -Dcsp.sentinel.dashboard.server=localhost:8081 -Dproject.name=sentinel-dashboard -jar sentinel-dashboard.jar 引數說明: -Dserver.port=8081:指定控制檯啟動埠 -Dcsp.sentinel.dashboard.server:指定控制檯地址和埠 -Dproject.name=sentinel-dashboard:指定控制檯專案名稱
localhost:8081,控制檯設定流控策略
說明:若需使用本地降級方法,需在下方的hello設定流控規則
jmeter 測試
2022-03-28 08:50:29.165 INFO 853 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port(s): 8080 (http) with context path '' 2022-03-28 08:50:29.198 INFO 853 --- [ main] c.a.c.n.registry.NacosServiceRegistry : nacos registry, DEFAULT_GROUP hello-sentinel 192.168.5.11:8080 register finished 2022-03-28 08:50:29.210 INFO 853 --- [ main] com.example.demo.DemoApplication : Started DemoApplication in 3.315 seconds (JVM running for 4.03) 2022-03-28 08:52:05.792 INFO 853 --- [nio-8080-exec-2] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring DispatcherServlet 'dispatcherServlet' 2022-03-28 08:52:05.793 INFO 853 --- [nio-8080-exec-2] o.s.web.servlet.DispatcherServlet : Initializing Servlet 'dispatcherServlet' 2022-03-28 08:52:05.802 INFO 853 --- [nio-8080-exec-2] o.s.web.servlet.DispatcherServlet : Completed initialization in 9 ms INFO: Sentinel log output type is: file INFO: Sentinel log charset is: utf-8 INFO: Sentinel log base directory is: /Users/huli/logs/csp/ INFO: Sentinel log name use pid is: false com.alibaba.csp.sentinel.slots.block.flow.FlowException com.alibaba.csp.sentinel.slots.block.flow.FlowException com.alibaba.csp.sentinel.slots.block.flow.FlowException com.alibaba.csp.sentinel.slots.block.flow.FlowException com.alibaba.csp.sentinel.slots.block.flow.FlowException com.alibaba.csp.sentinel.slots.block.flow.FlowException com.alibaba.csp.sentinel.slots.block.flow.FlowException com.alibaba.csp.sentinel.slots.block.flow.FlowException
到此這篇關於sentinel 整合spring cloud限流的過程解析的文章就介紹到這了,更多相關sentinel 整合spring cloud限流內容請搜尋it145.com以前的文章或繼續瀏覽下面的相關文章希望大家以後多多支援it145.com!
相關文章
<em>Mac</em>Book项目 2009年学校开始实施<em>Mac</em>Book项目,所有师生配备一本<em>Mac</em>Book,并同步更新了校园无线网络。学校每周进行电脑技术更新,每月发送技术支持资料,极大改变了教学及学习方式。因此2011
2021-06-01 09:32:01
综合看Anker超能充系列的性价比很高,并且与不仅和iPhone12/苹果<em>Mac</em>Book很配,而且适合多设备充电需求的日常使用或差旅场景,不管是安卓还是Switch同样也能用得上它,希望这次分享能给准备购入充电器的小伙伴们有所
2021-06-01 09:31:42
除了L4WUDU与吴亦凡已经多次共事,成为了明面上的厂牌成员,吴亦凡还曾带领20XXCLUB全队参加2020年的一场音乐节,这也是20XXCLUB首次全员合照,王嗣尧Turbo、陈彦希Regi、<em>Mac</em> Ova Seas、林渝植等人全部出场。然而让
2021-06-01 09:31:34
目前应用IPFS的机构:1 谷歌<em>浏览器</em>支持IPFS分布式协议 2 万维网 (历史档案博物馆)数据库 3 火狐<em>浏览器</em>支持 IPFS分布式协议 4 EOS 等数字货币数据存储 5 美国国会图书馆,历史资料永久保存在 IPFS 6 加
2021-06-01 09:31:24
开拓者的车机是兼容苹果和<em>安卓</em>,虽然我不怎么用,但确实兼顾了我家人的很多需求:副驾的门板还配有解锁开关,有的时候老婆开车,下车的时候偶尔会忘记解锁,我在副驾驶可以自己开门:第二排设计很好,不仅配置了一个很大的
2021-06-01 09:30:48
不仅是<em>安卓</em>手机,苹果手机的降价力度也是前所未有了,iPhone12也“跳水价”了,发布价是6799元,如今已经跌至5308元,降价幅度超过1400元,最新定价确认了。iPhone12是苹果首款5G手机,同时也是全球首款5nm芯片的智能机,它
2021-06-01 09:30:45