当前位置:网站首页>ZK configuration center -- configuration and use of config Toolkit
ZK configuration center -- configuration and use of config Toolkit
2022-07-02 09:37:00 【niceyz】
Config Toolkit brief introduction : Used in resource allocation center in distributed system , Instead of tradition properties file , advantage : Modify the configuration immediately and take effect immediately , There is no need for a new repackaged deployment project .
Download address :https://github.com/dangdangdotcom/config-toolkit
To configure zk, General configuration of production environment 5 platform , The configuration node is synchronized when it is created , Here, the default configuration is used , start-up zkServer.
Start project ( take config-face Pack it up jar perhaps war Deploy to server , at will ):
Input http://localhost:8080 Enter the login page :
Create node and password , Default The root node password is used sha1 encryption , Create password method ,( password :abc):
[[email protected] ~]# python -c "import hashlib;print hashlib.sha1('abc').hexdigest();"
a9993e364706816aba3e25717850c26c9cd0d89d
Create nodes :
1. Use zk client
create /projectx 1
create /projectx/modulex a9993e364706816aba3e25717850c26c9cd0d89d
2. Use java Code
<dependency>
<groupId>com.101tec</groupId>
<artifactId>zkclient</artifactId>
<version>0.10</version>
</dependency>
import org.I0Itec.zkclient.ZkClient;
import org.apache.zookeeper.CreateMode;
/**
* Created by yz on 2018/6/11.
*/
public class TestZookeeper {
public static void main(String[] args) {
// 60000 session Timeout time ;1000 Connection timeout
ZkClient zkClient = new ZkClient("127.0.0.1:2181", 60000, 10000);
// node ( route ); value ; Node type PERSISTENT Permanent nodes
//zkClient.create("/projectx","1", CreateMode.PERSISTENT);
zkClient.create("/projectx/modulex","a9993e364706816aba3e25717850c26c9cd0d89d", CreateMode.PERSISTENT);
zkClient.close();
System.out.println("### Registered successfully ###");
}
}
Use the node name :“/projectx/modulex”, password :“abc” Sign in , After logging in , Click on new Create version 1.0.0
Create groups separately , Create nodes
Use configuration :
1. The code gets the configuration directly :
import com.dangdang.config.service.GeneralConfigGroup;
import com.dangdang.config.service.zookeeper.ZookeeperConfigGroup;
import com.dangdang.config.service.zookeeper.ZookeeperConfigProfile;
/**
* @description:
* @author: yz
* @create: 2019/2/14 15:17
*/
public class YzDemo {
public static void main(String[] args) {
ZookeeperConfigProfile configProfile = new ZookeeperConfigProfile("localhost:2181", "/projectx/modulex", "1.0.0");
GeneralConfigGroup group = new ZookeeperConfigGroup(configProfile, "group");
String stringProperty = group.get("config.str");
System.out.println("stringProperty: "+stringProperty);
String intProperty = group.get("config.int");
System.out.println("intProperty: "+intProperty);
}
}
2.spring Injection allocation
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:config="https://crnlmchina.github.io/config"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
https://crnlmchina.github.io/config https://crnlmchina.github.io/config/config.xsd">
<config:profile connect-str="localhost:2181" root-node="/projectx/modulex" version="1.0.0"/>
<config:group id="groupProp" node="group"/>
<!-- Your business bean -->
<bean class="your.BusinessBean">
<property name="strProp" value="#{groupProp['config.str']}" />
<property name="intProp" value="#{groupProp['config.int']}" />
</bean>
</beans>
Corresponding zk node :
https://github.com/dangdangdotcom/config-toolkit
边栏推荐
- 每天睡觉前30分钟阅读_day4_Files
- 一次聊天勾起的回忆
- Solutions to Chinese garbled code in CMD window
- In depth analysis of how the JVM executes Hello World
- QT QLabel样式设置
- 微服务实战|Eureka注册中心及集群搭建
- Chrome browser tag management plug-in – onetab
- Customize redis connection pool
- Chrome浏览器标签管理插件–OneTab
- Timed thread pool implements request merging
猜你喜欢
idea查看字节码配置
Required request body is missing:(跨域问题)
Failed to configure a DataSource: ‘url‘ attribute is not specified and no embedd
MySQL multi column in operation
Pool de connexion redis personnalisé
Matplotlib swordsman - a stylist who can draw without tools and code
图像识别-数据标注
Watermelon book -- Chapter 5 neural network
Statistical learning methods - Chapter 5, decision tree model and learning (Part 1)
Matplotlib swordsman line - first acquaintance with Matplotlib
随机推荐
ClassFile - Attributes - Code
Learn combinelatest through a practical example
tinyxml2 读取和修改文件
Chrome user script manager tempermonkey monkey
Statistical learning methods - Chapter 5, decision tree model and learning (Part 1)
College Students' CET-4 and CET-6 composition template (self created version, successfully crossed CET-6)
保存视频 opencv::VideoWriter
Solutions to Chinese garbled code in CMD window
图像识别-数据标注
Methods of classfile
MySql报错:unblock with mysqladmin flush-hosts
上班第一天的报错(Nessus安装winpcap报错)
记录下对游戏主机配置的个人理解与心得
C语言之二进制与十进制
View the port of the application published by was
Customize redis connection pool
QT信号槽总结-connect函数错误用法
Beats (filebeat, metricbeat), kibana, logstack tutorial of elastic stack
Chrome浏览器插件-Fatkun安装和介绍
[go practical basis] how to verify request parameters in gin