SpringCloud-Sentine(熔断和监控)
Sentinel 是阿里巴巴开源的一款断路器实现
Sentinel与Hystrix的区别
一、配置管理控制台
- 下载sentinel-dashboard.jar
点这个连接直接下载1.3.0版:https://github.com/alibaba/Sentinel/releases/download/1.3.0/sentinel-dashboard-1.3.0-en.jar
或者进入https://github.com/alibaba/Sentinel/wiki/Dashboard 页面的标题2.1Download the dashboard
(sentinel中文文档地址:https://github.com/alibaba/Sentinel/wiki/%E4%BB%8B%E7%BB%8D )
(sentinel-dashboard.jar官方使用:https://github.com/alibaba/Sentinel/wiki/Dashboard)
- cmd中运行命令(sentinel的jar所在目录)
java -Dserver.port=8080 -Dcsp.sentinel.dashboard.server=localhost:8080 -
Dproject.name=sentinel-dashboard -jar sentinel-dashboard.jar
- 打开浏览器输入 http://localhost:8080
默认用户,密码都是sentinel,(参考https://github.com/alibaba/Sentinel/wiki/%E6%8E%A7%E5%88%B6%E5%8F%B0#%E9%89%B4%E6%9D%83 对用户密码配置)
默认情况下Sentinel 会在客户端首次调用的时候进行初始化,开始向控制台发送心跳包。也可以配置sentinel.eager=true ,取消Sentinel控制台懒加载(懒加载:只有访问该微服务才会在sentinel控制台监控到)。
二、项目配置
- 引入jar包依赖
非springcloud程序需要引入:
<dependency>
<groupId>com.alibaba.csp</groupId>
<artifactId>sentinel-transport-simple-http</artifactId>
</dependency>
springclou程序引入:
- 父工程
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-alibaba-dependencies </artifactId>
#注意这个版本,要和springcloud相关
<version>2.1.0.RELEASE</version>
<type>pom</type>
<scope>import</scope>
</dependency>
ps: spring-cloud-alibaba和spring-cloud有版本问题,需要配置对应的版本(https://github.com/alibaba/spring-cloud-alibaba/wiki/%E7%89%88%E6%9C%AC%E8%AF%B4%E6%98%8E)
- 子工程