当前位置: 首页 > news >正文

网站分享对联广告北京建设执业网站

网站分享对联广告,北京建设执业网站,宁波网络营销公司,什么是网站的推广上一篇我们介绍了如何通过改造Sentinel Dashboard来实现修改规则之后自动同步到Apollo。下面通过这篇#xff0c;详细介绍当使用Nacos作为配置中心之后#xff0c;如何实现Sentinel Dashboard中修改规则同步到Nacos。关于下面改造的原理和分析可以见上一篇《Sentinel Dashboa…上一篇我们介绍了如何通过改造Sentinel Dashboard来实现修改规则之后自动同步到Apollo。下面通过这篇详细介绍当使用Nacos作为配置中心之后如何实现Sentinel Dashboard中修改规则同步到Nacos。关于下面改造的原理和分析可以见上一篇《Sentinel Dashboard中修改规则同步到Apollo》的头两节内容这里不重复介绍了。 代码实现 下面直接来看看如何实现的具体改造步骤这里参考了Sentinel Dashboard源码中关于Nacos实现的测试用例。但是由于考虑到与Spring Cloud Alibaba的结合使用略作修改。 第一步修改pom.xml中的sentinel-datasource-nacos的依赖将scopetest/scope注释掉这样才能在主程序中使用。 dependency groupIdcom.alibaba.csp/groupId artifactIdsentinel-datasource-nacos/artifactId !--scopetest/scope--/dependency第二步找到resources/app/scripts/directives/sidebar/sidebar.html中的这段代码 li ui-sref-activeactive a ui-srefdashboard.flowV1({app: entry.app}) i classglyphicon glyphicon-filter/inbsp;nbsp;流控规则 /a/li修改为 li ui-sref-activeactive a ui-srefdashboard.flow({app: entry.app}) i classglyphicon glyphicon-filter/inbsp;nbsp;流控规则 /a/li第三步在com.alibaba.csp.sentinel.dashboard.rule包下新建一个nacos包用来编写针对Nacos的扩展实现。 第四步创建Nacos的配置类具体代码如下 Configurationpublic class NacosConfig { Bean public ConverterListFlowRuleEntity, String flowRuleEntityEncoder() { return JSON::toJSONString; } Bean public ConverterString, ListFlowRuleEntity flowRuleEntityDecoder() { return s - JSON.parseArray(s, FlowRuleEntity.class); } Bean public ConfigService nacosConfigService() throws Exception { Properties properties new Properties(); properties.put(PropertyKeyConst.SERVER_ADDR, localhost); return ConfigFactory.createConfigService(properties); }}如果用到了namespace隔离环境可以在nacosConfigService方法中再加入配置比如properties.put(PropertyKeyConst.NAMESPACE, 130e71fa-97fe-467d-ad77-967456f2c16d); 第五步实现Nacos的配置拉取。 Component(flowRuleNacosProvider)public class FlowRuleNacosProvider implements DynamicRuleProviderListFlowRuleEntity { Autowired private ConfigService configService; Autowired private ConverterString, ListFlowRuleEntity converter; public static final String FLOW_DATA_ID_POSTFIX -sentinel; public static final String GROUP_ID DEFAULT_GROUP; Override public ListFlowRuleEntity getRules(String appName) throws Exception { String rules configService.getConfig(appName FLOW_DATA_ID_POSTFIX, GROUP_ID, 3000); if (StringUtil.isEmpty(rules)) { return new ArrayList(); } return converter.convert(rules); }}getRules方法中的appName参数是Sentinel中的服务名称。configService.getConfig方法是从Nacos中获取配置信息的具体操作。其中DataId和GroupId分别对应客户端使用时候的对应配置。比如这里的例子对应了之前我们在《Sentinel使用Nacos存储规则》一文中的配置具体如下 spring.cloud.sentinel.datasource.ds.nacos.groupIdDEFAULT_GROUPspring.cloud.sentinel.datasource.ds.nacos.dataId${spring.application.name}-sentinel注意两边的DataId和GroupId必须对应上。 第六步实现Nacos的配置推送。 Component(flowRuleNacosPublisher)public class FlowRuleNacosPublisher implements DynamicRulePublisherListFlowRuleEntity { Autowired private ConfigService configService; Autowired private ConverterListFlowRuleEntity, String converter; public static final String FLOW_DATA_ID_POSTFIX -sentinel; public static final String GROUP_ID DEFAULT_GROUP; Override public void publish(String app, ListFlowRuleEntity rules) throws Exception { AssertUtil.notEmpty(app, app name cannot be empty); if (rules null) { return; } configService.publishConfig(app FLOW_DATA_ID_POSTFIX, GROUP_ID, converter.convert(rules)); }}这里的大部分内容与上一步中的实现一致。主要就是Nacos中存储配置的DataId和GroupId不要弄错。 第七步修改com.alibaba.csp.sentinel.dashboard.controller.v2.FlowControllerV2中DynamicRuleProvider和DynamicRulePublisher注入的Bean改为上面我们编写的针对Apollo的实现 AutowiredQualifier(flowRuleNacosProvider)private DynamicRuleProviderListFlowRuleEntity ruleProvider;AutowiredQualifier(flowRuleNacosPublisher)private DynamicRulePublisherListFlowRuleEntity rulePublisher;最后读者可以使用本文改造后的sentinel-dashboard联合之前《Sentinel使用Nacos存储规则》一文的例子来验证本文内容。 代码示例 本文介绍内容的客户端代码示例读者可以通过查看下面仓库中的alibaba-sentinel-dashboard-nacos项目 Githubhttps://github.com/dyc87112/SpringCloud-Learning/Giteehttps://gitee.com/didispace/SpringCloud-Learning/ 如果您对这些感兴趣欢迎star、follow、收藏、转发给予支持 系列回顾 《Spring Cloud Alibaba基础教程使用Nacos实现服务注册与发现》《Spring Cloud Alibaba基础教程支持的几种服务消费方式》《Spring Cloud Alibaba基础教程使用Nacos作为配置中心》《Spring Cloud Alibaba基础教程Nacos配置的加载规则详解》《Spring Cloud Alibaba基础教程Nacos配置的多环境管理》《Spring Cloud Alibaba基础教程Nacos配置的多文件加载与共享配置》《Spring Cloud Alibaba基础教程Nacos的数据持久化》《Spring Cloud Alibaba基础教程Nacos的集群部署》《Spring Cloud Alibaba基础教程使用Sentinel实现接口限流》《Spring Cloud Alibaba基础教程Sentinel使用Nacos存储规则》《Spring Cloud Alibaba基础教程Sentinel使用Apollo存储规则》《Spring Cloud Alibaba基础教程Sentinel Dashboard中修改规则同步到Apollo》 专题推荐 Spring Boot基础教程Spring Cloud基础教程
http://www.zqtcl.cn/news/569669/

相关文章:

  • 一级做爰片免费网站域名流量查询
  • 做网站网站需要注意什么网站建设swot市场分析
  • 大学生兼职网站的融资方案云凡济南网站建设开发
  • 做动态效果的插件网站抚顺清原网站建设招聘
  • 商务网站开发需求分析厦门35网站建设公司
  • wordpress classseo推广服务
  • 石景山网站建设公司网站后台密码如何破解
  • 哪个大学的网站做的最好看南宁网站设计制作公司
  • 北京 集团公司网站建设免费网站建设模版云盘
  • 阿里云建设网站要什么广州网站建设方案案例
  • 德阳吧网站建设线上编程培训机构哪家好
  • 天津电商网站开发备案查询站长之家
  • 网至普的营销型网站布局青岛做网站
  • 网站开发的安全问题wordpress文章列表显示缩略图
  • 网站运营招聘代理商加盟
  • 清远 网站建设自己做的网站怎么发布
  • 可以做免费推广的网站短视频app有哪些
  • 班级网站建设的系统概述wordpress品牌分类
  • 学做网站论坛第六节个人网站注册公司
  • 网站宣传怎样做不违法做网络平台的网站有哪些
  • 网站建设go邢台集团网站建设报价
  • 哪个网站做appwordpress改成织梦
  • 重庆南岸营销型网站建设公司推荐o2o平台网站建设
  • 网站建设横向发展纵向发展贵阳网站建设外包
  • 网站建设的解决方案南京网站搜索排名
  • 网站怎么做背景衡阳网页定制
  • h5做网站用什么软件中英版网站系统
  • 汕头中英文网站推广wordpress取回密码收不到邮件
  • 外贸在线网站建站wordpress开放注册
  • 桂林餐饮兼职网站建设如何在百度上建网站