本方案旨在尽可能少得变更官方原模块,以便于长期的迭代升级,避免对原模块的重复改造、测试工作。
以下是工程结构和定位:
__ sentinel-dashboard-datasource
|__ sentinel-dashboard (jar)
|__ sentinel-dashboard-datasource-nacos (jar)
|__ sentinel-dashboard-bridge(boot)
- sentinel-dashboard 是拷贝来自官方原模块,在本方案中视为后端模块,作为被依赖的jar包。
- sentinel-dashboard-datasource-nacos 是基于扩展机制实现配置持久化的模块。如:sentinel流控、熔断降级规则,作为被依赖的jar包。
- sentinel-dashboard-bridge 是真正构建和部署的控制台应用。其主要作用是前端模块,链接持久化模块。作为执行应用软件包。
- 复制官方原模块
- 仅在原官方模块,pom.xml中添加:
<!--移除资源模块,将原boot打包成纯粹的jar-->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>jar</goal>
</goals>
<phase>package</phase>
<configuration>
<classifier>backend</classifier>
<excludes>
<exclude>**/resources/**</exclude>
</excludes>
</configuration>
</execution>
</executions>
</plugin>- 执行构建打包成可被依赖的jar包:
<dependency>
<groupId>com.alibaba.csp</groupId>
<artifactId>sentinel-dashboard</artifactId>
<classifier>backend</classifier>
<version>${sentinel.version}</version>
</dependency>- 新建模块。
- 添加依赖
com.alibaba.csp:sentinel-dashboard:backend和com.alibaba.csp:sentinel-datasource-extension,采用官方扩展机制DynamicRuleProvider和DynamicRulePublisher实现动态规则的发布和查询,此模块运用Nacos持久化存储。 - 定义并实现Controller为应用预设资源访问入口,并运用DynamicRuleNacosProvider和DynamicRuleNacosPublisher。参考:官方集群持久化扩展机制
- 执行构建打包成可被依赖的jar包:
<dependency>
<groupId>com.sirius.to</groupId>
<artifactId>sentinel-dashboard-datasource-nacos</artifactId>
<version>1.0.0-SNAPSHOT</version>
</dependency>- 新建模块。
- 依赖
com.alibaba.csp:sentinel-dashboard:backend和com.sirius.to:sentinel-dashboard-datasource-nacos,使得该模块具备动态规则持久化和原控制台所有"后端"能力。 - 复制原官方模块下
resources和webapp,使得该模块具备参数配置和web应用能力。 - 改造
webapp,使得该模块正确接入Controller(如:DegradeControllerV3、FlowControllerV3等)资源。 - 构建打包成可执行的boot包(应用软件包):
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>${spring.boot.version}</version>
<configuration>
<fork>true</fork>
<mainClass>com.alibaba.csp.sentinel.dashboard.DashboardApplicationX</mainClass>
</configuration>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>mvn clean package使用如下命令启动编译后的控制台:
java -Dserver.port=8722 \
-Dcsp.sentinel.dashboard.server=localhost:8723 \
-Dnacos.server.addr=127.0.0.1 \
-Dnacos.server.port=8848 \
-Dproject.name=sentinel-dashboard \
-jar target/sentinel-dashboard-bridge-1.0.0-SNAPSHOT.jarhttp://localhost:8722/#/dashboard/home

