Spring Cloud Alibaba使用Sentinel限流_四

2019独角兽企业重金招聘Python工程师标准>>> hot3.png

阿里的Sentinel 是面向分布式服务架构的轻量级流量控制产品,主要以流量为切入点,从流量控制、熔断降级、系统负载保护等多个维度来帮助您保护服务的稳定性。这里我们使用Spring Cloud Alibaba集成Sentinel。

在原来的项目中引入依赖,版本好使用的是>0.2.1.RELEASE,在dependencyManagement控制。

Spring Cloud Alibaba使用Sentinel限流_四_第1张图片

因为spring-cloud-alibaba还没有加入spring-cloud的版本控制,所以还是要自己引入的

Spring Cloud Alibaba使用Sentinel限流_四_第2张图片

然后实现起来就比较简单了,这里加入一个注解com.alibaba.csp.sentinel.annotation.SentinelResource

ea6ffc3a80371197ee5c2760eba8ffe2076.jpg

然后还需要添加一个配置

Spring Cloud Alibaba使用Sentinel限流_四_第3张图片

然后我们使用Sentinel控制台来配置限流规则

我们简单一点直接下载 Sentinel控制台,http://edas-public.oss-cn-hangzhou.aliyuncs.com/install_package/demo/sentinel-dashboard.jar

然后执行java -jar sentinel-dashboard.jar就可以啦

Spring Cloud Alibaba使用Sentinel限流_四_第4张图片

然后我们在本地的8080端口,打开

Spring Cloud Alibaba使用Sentinel限流_四_第5张图片

然后我配置一个限流

Spring Cloud Alibaba使用Sentinel限流_四_第6张图片

然后我们访问一下这个接口,因为配置的一秒内只会处理一个,所以第二个被拦截啦。

e1d130830ea294f216d11b58e58033d42a2.jpg

git:https://github.com/woshiyexinjie/boot-two/tree/master/cloud-alibaba

参考:

https://github.com/spring-cloud-incubator/spring-cloud-alibaba/blob/master/spring-cloud-alibaba-examples/sentinel-example/sentinel-core-example/readme-zh.md

 

 

 

 

转载于:https://my.oschina.net/u/2277632/blog/3017593

你可能感兴趣的:(Spring Cloud Alibaba使用Sentinel限流_四)