這個可以用來做流控肤舞,監(jiān)控等,效果要比cloud 的 Hystrix效果要好很多
1.1 建立項目,加入POM的依賴
<!--阿里巴巴流控組件-->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-sentinel</artifactId>
</dependency>
1.2 增加對應(yīng)的配置文件
spring.application.name=demo-alibaba-springcloud-sentinel
server.port=8001
# sentinel dashboard
spring.cloud.sentinel.transport.dashboard=localhost:8080
1.3 代碼中增加一個簡單的接口
@RestController
public class SentinelController {
@GetMapping("/get")
public Object test(){
return "hello word";
}
}
1.4 啟動這個中間件程序 sentinel溢陪, 注意我們盡量使用和阿里巴巴cloud版本一致的sentinel
https://github.com/alibaba/Sentinel/releases
java -jar sentinel.jar
1.5 查看效果如下
在對應(yīng)的地方和接口咏连,配置限流即可。