Sentinel demo
Sentinel 新手指南
Sentinel 分布式系统的流量防卫兵。
Sentinel 是什么?
随着微服务的流行,服务和服务之间的稳定性变得越来越重要。Sentinel 以流量为切入点,从流量控制、熔断降级、系统负载保护等多个维度保护服务的稳定性。
参考:https://github.com/alibaba/Sentinel/wiki/%E6%96%B0%E6%89%8B%E6%8C%87%E5%8D%97#%E5%85%AC%E7%BD%91-demo
Sentinel 源码项目
github 地址:https://github.com/alibaba/Sentinel
项目结构:
启动:DashboardApplication.java 类型
端口: 8080
Sentinel 客户端项目
新建立一个项目 spring-boot-sentinel
pom.xml 引入依赖 <!-- Sentinel --> <dependency> <groupId>com.alibaba.csp</groupId> <artifactId>sentinel-core</artifactId> <version>1.8.3</version> </dependency> <dependency> <groupId>com.alibaba.csp</groupId> <artifactId>sentinel-transport-spring-mvc</artifactId> <version>1.8.3</version> </dependency> <!-- Transport 模块来与 Sentinel 控制台进行通信 --> <dependency> <groupId>com.alibaba.csp</groupId> <artifactId>sentinel-transport-simple-http</artifactId> <version>1.8.3</version> </dependency>
使用 sentinel 源码中的 demo 代码,TransportSpringMvcDemoApplication.java 类
1.启动类@SpringBootApplication public class DemoApplication {public static void main(String[] args) {triggerSentinelInit();initFlowRules();SpringApplication.run(DemoApplication.class, args);}private static void triggerSentinelInit() {new Thread(() -> InitExecutor.doInit()).start();}public static void initFlowRules() {List<FlowRule> rules = new ArrayList<>();FlowRule rule = new FlowRule();rule.setResource("demo-hello-api");rule.setGrade(RuleConstant.FLOW_GRADE_QPS);// 设置 QPS 数rule.setCount(1);rules.add(rule);FlowRuleManager.loadRules(rules);}@Beanpublic SentinelApiHandlerMapping sentinelApiHandlerMapping() {return new SentinelApiHandlerMapping();}@Beanpublic SentinelApiHandlerAdapter sentinelApiHandlerAdapter() {return new SentinelApiHandlerAdapter();}}2.控制接口类 @RestController public class DemoController {@GetMapping("/hello")@ResponseBodypublic String hello() {Entry entry = null;try {entry = SphU.entry("demo-hello-api");return "ok: " + LocalDateTime.now();} catch (BlockException e1) {return "helloBlockHandler: " + LocalDateTime.now();} finally {if (entry != null) {entry.exit();}}}}
启动时加入 JVM 参数:
VM options: -Dcsp.sentinel.dashboard.server=127.0.0.1:8080
启动端口
server.port=8081
使用 Api Post 调试:
通过设置不同的 QPS 数,查看是否有 helloBlockHandler 的异常处理结果,能判断出 Sentinel 的功能是否起效果。
Dashboard 控制台
地址:http://localhost:8080/ 默认登录账号: sentinel / sentinel
Sentinel demo相关推荐
- Sentinel 发布里程碑版本,添加集群流控功能
为什么80%的码农都做不了架构师?>>> 自去年10月底发布GA版本后,Sentinel在近期发布了另一个里程碑版本v1.4(最新的版本号是v1.4.1),加入了开发者关注的集 ...
- gateway sentinel 熔断 不起作用_Spring Cloud Alibaba集训营第五天(服务熔断和限流)
前言:为什么需要流控降级 我们的生产环境经常会出现一些不稳定的情况,如: 大促时瞬间洪峰流量导致系统超出最大负载,load 飙高,系统崩溃导致用户无法下单 "黑马"热点商品击穿缓存 ...
- Sentinel(十九)之主流框架的适配
转载自 主流框架的适配 注:适配模块仅提供相应适配功能,若希望接入 Sentinel 控制台,请务必参考 Sentinel 控制台文档. 云原生微服务体系 Spring Cloud Spring C ...
- Sentinel(十三)之动态规则扩展
转载自 动态规则扩展 规则 Sentinel 的理念是开发者只需要关注资源的定义,当资源定义成功后可以动态增加各种流控降级规则.Sentinel 提供两种方式修改规则: 通过 API 直接修改 (l ...
- 实践 | Sentinel 扩展性设计
Sentinel 提供多样的 SPI 接口用于提供扩展的能力.用户可以在用同一个 sentinel-core 的基础上自行扩展接口实现,从而可以方便地给 Sentinel 添加自定义的逻辑. 初始化逻 ...
- 实践 | Sentinel 扩展性设计 1
摘要: Sentinel 提供多样的 SPI 接口用于提供扩展的能力.用户可以在用同一个 sentinel-core 的基础上自行扩展接口实现,从而可以方便地给 Sentinel 添加自定义的逻辑. ...
- sentinel限流相关指标统计源码分析
文章目录 *前言* *官方架构图* 滑动窗口模型 *StatisticSlot* *Node* *NodeSelectorSlot* *ClusterBuilderSlot* *FlowSlot如何使 ...
- 阿里sentinel监控客户端配置
第一种配置方式: 1.客户端application.properties文件配置 spring.application.name=sentinel-example server.port=8900## ...
- Sentinel整合Dubbo限流实战
Sentinel整合Dubbo限流实战 创建provider项目 添加jar依赖 <dependency><artifactId>sentinel-api</artifa ...
最新文章
- 解决 mac ox 终端显示bogon 的问题
- Java小青蛙跳台街,青蛙跳台阶问题:Java版,递归算法和循环
- 一步步编写操作系统81 att内嵌汇编语法
- 模态窗口插件之Jbox
- 阿里与网易考拉收购案谈崩?后者股价下跌5.01%
- Integer学习感悟
- Python Profiler 列举
- 吊打面试官系列:你会「递归」么?
- 【工具】(转)PowerDesigner最基础的使用方法入门学习
- 编译libxcb时报错:No package 'xcb-proto' found
- 服装设计与工程_百度百科
- mysql2008 密钥_怎么查看sql server 2008密钥
- 推荐几个火狐浏览器插件
- 实型变量的定义和应用
- docker出现问题:You cannot remove a running container 解决方案
- 算法导论第十二章总结以及课后题答案
- A3A1自助申请PHP版搭建,微软全局子号-微软全局订阅A3桌面版office账号自助申请程序下载php版-西西软件下载...
- adb shell appops(系统服务:appops)
- 基于51单片机的出租车计价器的设计
- 算法与数据结构实验题 7.4 玩游戏的亚索 (最小支撑树)