In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly explains "how to use Sentinel Dashboard dynamic push to synchronize data to Nacos". The content of the article is simple and clear, and it is easy to learn and understand. Please follow the editor's ideas to study and learn "how to use Sentinel Dashboard dynamic push to synchronize data to Nacos".
Preparatory work:
Download the release version of Sentinel Dashboard. Address: https://github.com/alibaba/Sentinel/releases
One: modify the dependency of sentinel-datasource-nacos in pom.xml and comment out test so that it can be used in the main program.
Com.alibaba.csp sentinel-datasource-nacos
Two: find this code in resources/app/scripts/directives/sidebar/sidebar.html:
Flow control rules
Modified to:
Flow control rules
After this modification, you will jump to the interface of FlowControllerV2.
Third: create a new nacos package in the project com.alibaba.csp.sentinel.dashboard to achieve the extended function.
@ Component@ConfigurationProperties (prefix = "nacos.server") public class NacosConfigProperties {private String ip; private String port; private String namespace; private String groupId; public String getIp () {return ip;} public void setIp (String ip) {this.ip = ip;} public String getPort () {return port;} public void setPort (String port) {this.port = port } public String getNamespace () {return namespace;} public void setNamespace (String namespace) {this.namespace = namespace;} public String getGroupId () {return groupId;} public void setGroupId (String groupId) {this.groupId = groupId;} public String getServerAddr () {return this.getIp () + ":" + this.getPort () } @ Override public String toString () {return "NacosConfigProperties [ip=" + ip + ", port=" + port + ", namespace=" + namespace + ", groupId=" + groupId + "]";}} public final class NacosConfigConstant {public static final String FLOW_DATA_ID_POSTFIX = "- sentinel-flow"; public static final String GROUP_ID = "DEFAULT_GROUP";} @ Configurationpublic class NacosConfig {@ Autowired private NacosConfigProperties nacosConfigProperties / * it is very important to convert FlowRuleEntity to FlowRule before it takes effect on the client * @ return FlowRule * / @ Bean public Converter flowRuleEntityEncoder () {return rules-> JSON.toJSONString (rules.stream (). Map (FlowRuleEntity::toRule) .clients (Collectors.toList ()), true);} @ Bean public Converter flowRuleEntityDecoder () {return s-> JSON.parseArray (s, FlowRuleEntity.class) @ Bean public ConfigService nacosConfigService () throws Exception {Properties properties = new Properties (); properties.put (PropertyKeyConst.SERVER_ADDR, nacosConfigProperties.getServerAddr ()); properties.put (PropertyKeyConst.NAMESPACE, nacosConfigProperties.getNamespace ()); return ConfigFactory.createConfigService (properties);}}
Four: write the extension code of dynamic push-pull mode
@ Component ("flowRuleNacosProvider") public class FlowRuleNacosProvider implements DynamicRuleProvider {private static Logger logger = LoggerFactory.getLogger (FlowRuleNacosProvider.class); @ Autowired private NacosConfigProperties nacosConfigProperties; @ Autowired private ConfigService configService; @ Autowired private Converter converter; @ Override public List getRules (String appName) throws Exception {String rules = configService.getConfig (appName + NacosConfigConstant.FLOW_DATA_ID_POSTFIX, nacosConfigProperties.getGroupId (), 3000); logger.info ("pull current restriction rule information from Nacos: {}", rules) If (StringUtil.isEmpty (rules)) {return new ArrayList ();} return converter.convert (rules);} @ Component ("flowRuleNacosPublisher") public class FlowRuleNacosPublisher implements DynamicRulePublisher {@ Autowired private NacosConfigProperties nacosConfigProperties; @ Autowired private ConfigService configService; @ Autowired private Converter converter; @ Override public void publish (String app, List rules) throws Exception {AssertUtil.notEmpty (app, "app name cannot be empty") If (rules = = null) {return;} configService.publishConfig (app + NacosConfigConstant.FLOW_DATA_ID_POSTFIX, nacosConfigProperties.getGroupId (), converter.convert (rules));}
Five: then modify the default DynamicRuleProvider and DynamicRulePublisher in FlowControllerV2 to:
@ Autowired@Qualifier ("flowRuleNacosProvider") private DynamicRuleProvider ruleProvider;@Autowired@Qualifier ("flowRuleNacosPublisher") private DynamicRulePublisher rulePublisher;private void publishRules (/ * @ NonNull*/ String app) throws Exception {List rules = repository.findAllByApp (app); rulePublisher.publish (app, rules); logger.info ("add current restriction rules successfully {}", JSON.toJSONString (rules.stream (). Map (FlowRuleEntity::toRule) .limits (Collectors.toList ()), true);}
Six: application.properties configuration file
# nacosnacos.server.ip=localhostnacos.server.port=8848nacos.server.namespace=nacos.server.group-id=DEFAULT_GROUP Thank you for your reading. The above is the content of "how to use Sentinel Dashboard dynamic push to synchronize data to Nacos". After the study of this article, I believe you have a deeper understanding of how to use Sentinel Dashboard dynamic push to synchronize data to Nacos, and the specific usage needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 271
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.