Skip to content

基于alibaba/Sentinel/sentinel-dashboard进行的配置中心配置持久化改造

License

Notifications You must be signed in to change notification settings

vtroisWhite/vtrois-sentinel

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

将sentinel配置持久化到nacos、zookeeper

基于sentinel-dashboard二次开发, 版本1.8.6

sentinel-dashboard 二次开发的sentinel配置后台

实现的功能

  • 后端配置持久化到nacos、zookeeper,可通过application.properties spring.profiles.active 进行配置
  • 新增了 client/config 接口,返回客户端需要监控的配置文件路径,防止出现客户端手动配置的不一致的问题,配置示例:
{
  "success": true,
  "code": 0,
  "msg": "success",
  "data": {
    "zkConfig": {
      "address": "test.zk.localhost",
      "rulePath": {
        "flowPath": "/sentinel_rules/sentinel-client-demo/flow",
        "degradePath": "/sentinel_rules/sentinel-client-demo/degrade",
        "paramFlowPath": "/sentinel_rules/sentinel-client-demo/paramFlow",
        "systemRulePath": "/sentinel_rules/sentinel-client-demo/systemRules",
        "authorityRulePath": "/sentinel_rules/sentinel-client-demo/authorityRules",
        "gatewayFlowRuleRulePath": "/sentinel_rules/sentinel-client-demo/gatewayFlowRules",
        "gatewayApiDefinitionPath": "/sentinel_rules/sentinel-client-demo/gatewayApiGroupRules",
        "clusterModePath": "/sentinel_rules/sentinel-client-demo/clusterModeRules",
        "clusterClientConfigPath": "/sentinel_rules/sentinel-client-demo/clusterClientConfigRules",
        "clusterServerFlowPath": "/sentinel_rules/sentinel-client-demo/clusterServerFlowRules",
        "clusterServerTransportPath": "/sentinel_rules/sentinel-client-demo/clusterServerTransportRules",
        "clusterServerNamespacePath": "/sentinel_rules/sentinel-client-demo/clusterServerNamespaceRules"
      }
    },
    "nacosConfig": {
      "address": "test.nacos.localhost:80",
      "namespace": "sentinel-config",
      "username": "nacos",
      "password": "nacos",
      "groupId": "DEFAULT_GROUP",
      "rulePath": {
        "flowPath": "sentinel-client-demo-flow-rules",
        "degradePath": "sentinel-client-demo-degrade-rules",
        "paramFlowPath": "sentinel-client-demo-param-rules",
        "systemRulePath": "sentinel-client-demo-system-rules",
        "authorityRulePath": "sentinel-client-demo-authority-rules",
        "gatewayFlowRuleRulePath": "sentinel-client-demo-gateway-flow-rules",
        "gatewayApiDefinitionPath": "sentinel-client-demo-gateway-api-group-rules",
        "clusterModePath": "sentinel-client-demo-cluster-mode-rules",
        "clusterClientConfigPath": "sentinel-client-demo-cluster-client-config-rules",
        "clusterServerFlowPath": "sentinel-client-demo-cluster-serve-flow-rules",
        "clusterServerTransportPath": "sentinel-client-demo-cluster-server-transport-rules",
        "clusterServerNamespacePath": "sentinel-client-demo-cluster-server-namespace-rules"
      }
    }
  }
}

改造说明 (git修改记录)

  • 将原本官方的获取配置接口DynamicRuleProvider,发布配置接口DynamicRulePublisher,聚合为了一个接口:DynamicRuleService.java
  • 并以此接口为基础,实现了通过 nacoszookeeper 对配置进行获取与发布的实现
  • 新增SentinelCustomApiClient.java 并继承覆盖了 SentinelApiClient.java 将原本调用client客户端进行获取配置、更新配置的操作,改为修改nacos、zookeeper中的配置,并且客户端监控中间件的配置文件变化,同时更新配置
  • 新增api接口ClientConfigController.java 获取当前服务端中间件的配置信息,客户端可以直接连接配置更新配置文件,无需在客户端再维护一套配置
  • 项目启动时EnvObjectConfig.java会通过environment.plugin配置来加载使用nacos或者zookeeper为中间件

sentinel-client-demo 客户端加载使用sentinel Demo

项目启动需要配置以下启动参数

-Dproject.name=sentinel-client-demo -Dcsp.sentinel.dashboard.server=127.0.0.1:8901 -Dcsp.sentinel.api.port=8719 -Dcsp.sentinel.log.dir=./logs/sentinel/ -Dcsp.sentinel.log.use.pid=true -Dcsp.sentinel.log.output.type=console

代码说明

About

基于alibaba/Sentinel/sentinel-dashboard进行的配置中心配置持久化改造

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published