sentinel基于nacos的持久化,改造sentinel-dashboard-1.8

修改 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>&nbsp;&nbsp;流控规则-v2 </a></li>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值