Spring Cloud Alibaba之 Sentinel( 四 )


默认情况下 , xml 格式是不支持的 。 需要添加 jackson-dataformat-xml 依赖后才会自动生效 。
关于 Sentinel 动态数据源的实现原理 , 参考: 动态规则扩展
Zuul 支持参考 Sentinel 网关限流
若想跟 Sentinel Starter 配合使用 , 需要加上 spring-cloud-alibaba-sentinel-gateway 依赖 , 同时需要添加 spring-cloud-starter-netflix-zuul 依赖来让 spring-cloud-alibaba-sentinel-gateway 模块里的 Zuul 自动化配置类生效:
com.alibaba.cloudspring-cloud-starter-alibaba-sentinelcom.alibaba.cloudspring-cloud-alibaba-sentinel-gatewayorg.springframework.cloudspring-cloud-starter-gatewaySpring Cloud Gateway 支持参考 Sentinel 网关限流
若想跟 Sentinel Starter 配合使用 , 需要加上 spring-cloud-alibaba-sentinel-gateway 依赖 , 同时需要添加 spring-cloud-starter-gateway 依赖来让 spring-cloud-alibaba-sentinel-gateway 模块里的 Spring Cloud Gateway 自动化配置类生效:
com.alibaba.cloudspring-cloud-starter-alibaba-sentinelcom.alibaba.cloudspring-cloud-alibaba-sentinel-gatewayorg.springframework.cloudspring-cloud-starter-gatewaySentinel 对外暴露的 EndpointSentinel 内部提供了一个 Endpoint, 对应的 endpoint id 为 sentinel 。
Endpoint 暴露的 json 中包含了多种属性:

  1. appName: 应用名
  2. logDir: 日志所在目录
  3. logUsePid: 日志文件名是否带上进程id
  4. blockPage: 限流 block 之后跳转的页面
  5. metricsFileSize: metrics 文件的大小
  6. metricsFileCharset: metrics 文件对应的字符集
  7. totalMetricsFileCount: metrics 最多保留的文件数
  8. consoleServer: sentinel dashboard 地址
  9. clientIp: 客户端 ip
  10. heartbeatIntervalMs: 客户端跟 dashboard 的心跳间隔时间
  11. clientPort: 客户端需要暴露的端口跟 dashboard 进行交互
  12. coldFactor: 冷启动因子
  13. filter: CommonFilter 相关的属性 ,比如 order, urlPatterns 以及 enable
  14. datasource: 客户端配置的数据源信息
  15. rules: 客户端生效的规则 , 内部含有 flowRules, degradeRules, systemRules, authorityRule, paramFlowRule
这是 Endpoint 暴露的 json 示例:
【Spring Cloud Alibaba之 Sentinel】{ "blockPage": null, "appName": "sentinel-example", "consoleServer": "localhost:8080", "coldFactor": "3", "rules": {"flowRules": [{"resource": "GET:","limitApp": "default","grade": 1,"count": 0.0,"strategy": 0,"refResource": null,"controlBehavior": 0,"warmUpPeriodSec": 10,"maxQueueingTimeMs": 500,"clusterMode": false,"clusterConfig": null}, {"resource": "/test","limitApp": "default","grade": 1,"count": 0.0,"strategy": 0,"refResource": null,"controlBehavior": 0,"warmUpPeriodSec": 10,"maxQueueingTimeMs": 500,"clusterMode": false,"clusterConfig": null}, {"resource": "/hello","limitApp": "default","grade": 1,"count": 1.0,"strategy": 0,"refResource": null,"controlBehavior": 0,"warmUpPeriodSec": 10,"maxQueueingTimeMs": 500,"clusterMode": false,"clusterConfig": null}] }, "metricsFileCharset": "UTF-8", "filter": {"order": -2147483648,"urlPatterns": ["/*"],"enabled": true }, "totalMetricsFileCount": 6, "datasource": {"ds1": {"file": {"dataType": "json","ruleType": "FLOW","converterClass": null,"file": "...","charset": "utf-8","recommendRefreshMs": 3000,"bufSize": 1048576},"nacos": null,"zk": null,"apollo": null,"redis": null} }, "clientIp": "30.5.121.91", "clientPort": "8719", "logUsePid": false, "metricsFileSize": 52428800, "logDir": "...", "heartbeatIntervalMs": 10000}