同步操作将从 JbootProjects/jboot 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
随着微服务的流行,服务和服务之间的稳定性变得越来越重要。Sentinel 以流量为切入点,从流量控制、熔断降级、系统负载保护等多个维度保护服务的稳定性。
Sentinel 具有以下特征:
Sentinel 分为两个部分:
核心库(Java 客户端)不依赖任何框架/库,能够运行于所有 Java 运行时环境,同时对 Dubbo / Spring Cloud 等框架也有较好的支持。 控制台(Dashboard)基于 Spring Boot 开发,打包后可以直接运行,不需要额外的 Tomcat 等应用容器。
更多的文档请参考:
https://github.com/alibaba/Sentinel/wiki/%E4%BB%8B%E7%BB%8D
第一步,启动 Sentinel dashboard:
下载 Sentinel 的 jar 到本地,并通过如下方式启动 启动 sentinel dashboard
java -jar sentinel-dashboard-1.8.0.jar
jar 的下载地址:https://github.com/alibaba/Sentinel/releases
启动时,默认端口号为:8080,可以通过 -Dserver.port=8888 用于指定 Sentinel 控制台端口为 8888。
例如:
java -Dserver.port=8888 -jar sentinel-dashboard-1.8.0.jar
从 Sentinel 1.6.0 起,Sentinel 控制台引入基本的登录功能,默认用户名和密码都是 sentinel。
可以通过如下配置来修改掉默认的账号和密码:
关于控制台的更多配置,请参考: https://github.com/alibaba/Sentinel/wiki/%E6%8E%A7%E5%88%B6%E5%8F%B0#%E6%8E%A7%E5%88%B6%E5%8F%B0%E9%85%8D%E7%BD%AE%E9%A1%B9
第二步:配置项目的 sentinel.properties 和 Maven 依赖
在项目的 resource 目录下创建 sentinel.properties 文本,并配置相关信息如下:
csp.sentinel.dashboard.server=localhost:8080
关于更多 sentinel.properties 的配置请参考:
添加 maven 依赖:
<dependency>
<groupId>com.alibaba.csp</groupId>
<artifactId>sentinel-core</artifactId>
<version>${sentinel.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.alibaba.csp</groupId>
<artifactId>sentinel-cluster-client-default</artifactId>
<version>${sentinel.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.alibaba.csp</groupId>
<artifactId>sentinel-transport-simple-http</artifactId>
<version>${sentinel.version}</version>
<scope>provided</scope>
</dependency>
第三步:配置限流资源
在项目的任意目录下,使用注解 @SentinelResource
给方法进行配置,代码如下:
@RequestMapping("/sentinel")
public class SentinelController extends JbootController {
@SentinelResource
public void index(){
renderText("sentinel index...");
}
}
或者在 Service 中
public class UserService{
// 原本的业务方法.
@SentinelResource(blockHandler = "blockHandlerForGetUser")
public User getUserById(String id) {
throw new RuntimeException("getUserById command failed");
}
// blockHandler 函数,原方法调用被限流/降级/系统保护的时候调用
public User blockHandlerForGetUser(String id, BlockException ex) {
return new User("admin");
}
}
然后通过浏览器进入 sentinel dashboard 中心,对 SentinelController.index()
和 UserService.getUserById()
的资源进行具体的限流参数配置。
关注注解 @SentinelResource
更多的配置,请参考文档: https://github.com/alibaba/Sentinel/wiki/%E6%B3%A8%E8%A7%A3%E6%94%AF%E6%8C%81#sentinelresource-%E6%B3%A8%E8%A7%A3
更多的 sentinel dashboard 配置内容请参考:https://github.com/alibaba/Sentinel/wiki/%E6%8E%A7%E5%88%B6%E5%8F%B0
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。