修改 sentinel-dashboard(sentinel-dashboard)
修改 com.alibaba.csp.sentinel.dashboard.controller.v2.FlowControllerV2 中 配置注入的路径改为nacos
@RestController
@RequestMapping(value = "/v2/flow")
public class FlowControllerV2 {
@Autowired
@Qualifier("flowRuleNacosProvider")
private DynamicRuleProvider<List<FlowRuleEntity>> ruleProvider;
@Autowired
@Qualifier("flowRuleNacosPublisher")
private DynamicRulePublisher<List<FlowRuleEntity>> rulePublisher;
复制test --下面com.alibaba.csp.sentinel.dashboard.rule.nacos的4个类到 mian-java-com.alibaba.csp.sentinel.dashboard.rule,并修改NacosConfig类中的信息,指定路径,命名空间,和集群名称,创建Properties(nacos的配置类),将指定信息写入,key是 PropertyKeyConst中的常量,value是你的值,放入到
@Configuration
public class NacosConfig {
@Value("${naocs.address}")
private String address;
@Value("${nacos.namespace}")
private String namespace;
@Value("${nacos.clusterName}")
private String clusterName;
@Bean
public Converter<List<FlowRuleEntity>, String> flowRuleEntityEncoder() {
return JSON::toJSONString;
}
@Bean
public Converter<String, List<FlowRuleEntity>> flowRuleEntityDecoder() {
return s -> JSON.parseArray(s, FlowRuleEntity.class);
}
@Bean
public ConfigService nacosConfigService() throws Exception { //服务配置
Properties properties = new Properties(); //定义nacos的配置属性
properties.put(PropertyKeyConst.SERVER_ADDR,this.address);
properties.put(PropertyKeyConst.NAMESPACE,this.namespace);
properties.put(PropertyKeyConst.CLUSTER_NAME,this.clusterName);
return ConfigFactory.createConfigService(properties);
}
}
@Configuration
public class NacosConfig {
@Value("${naocs.address}")
private String address;
@Value("${nacos.namespace}")
private String namespace;
@Value("${nacos.clusterName}")
private String clusterName;
@Bean
public Converter<List<FlowRuleEntity>, String> flowRuleEntityEncoder() {
return JSON::toJSONString;
}
@Bean
public Converter<String, List<FlowRuleEntity>> flowRuleEntityDecoder() {
return s -> JSON.parseArray(s, FlowRuleEntity.class);
}
@Bean
public ConfigService nacosConfigService() throws Exception { //服务配置
Properties properties = new Properties(); //定义nacos的配置属性
properties.put(PropertyKeyConst.SERVER_ADDR,this.address);
properties.put(PropertyKeyConst.NAMESPACE,this.namespace);
properties.put(PropertyKeyConst.CLUSTER_NAME,this.clusterName);
return ConfigFactory.createConfigService(properties);
}
}
修改前端页面
sentinel-dashboard/src/main/webapp/resources/app/scripts/directives/sidebar/sidebar.html
解除注释
<li ui-sref-active="active" ng-if="entry.appType==0"> <a ui-sref="dashboard.flow({app: entry.app})"> <i class="glyphicon glyphicon-filter"></i> 流控规则-v2 </a></li>