当前位置:网站首页>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
边栏推荐
- 一次聊天勾起的回忆
- Read Day5 30 minutes before going to bed every day_ All key values in the map, how to obtain all value values
- 保存视频 opencv::VideoWriter
- BugkuCTF-web21(详细解题思路及步骤)
- What are the waiting methods of selenium
- Read Day6 30 minutes before going to bed every day_ Day6_ Date_ Calendar_ LocalDate_ TimeStamp_ LocalTime
- 每天睡觉前30分钟阅读_day4_Files
- CKEditor 4.10.1 上传图片提示“不正确的服务器响应” 问题解决
- How to install PHP in CentOS
- Microservice practice | declarative service invocation openfeign practice
猜你喜欢
In depth analysis of how the JVM executes Hello World
Activity的创建和跳转
[go practical basis] how to customize and use a middleware in gin
Statistical learning methods - Chapter 5, decision tree model and learning (Part 1)
知识点很细(代码有注释)数构(C语言)——第三章、栈和队列
Solutions to Chinese garbled code in CMD window
Fragmenttabhost implements the interface of housing loan calculator
Navicat remote connection MySQL reports an error 1045 - access denied for user 'root' @ '222.173.220.236' (using password: yes)
别找了,Chrome浏览器必装插件都在这了
[go practical basis] gin efficient artifact, how to bind parameters to structures
随机推荐
kinect dk 获取CV::Mat格式的彩色RGB图像(openpose中使用)
一次聊天勾起的回忆
机器学习实战:《美人鱼》属于爱情片还是动作片?KNN揭晓答案
Customize redis connection pool
Chrome browser plug-in fatkun installation and introduction
Long summary (code with comments) number structure (C language) -- Chapter 4, string (Part 1)
Enterprise level SaaS CRM implementation
C语言之数据插入
Typora installation package sharing
分享一篇博客(水一篇博客)
每天睡前30分钟阅读Day6_Day6_Date_Calendar_LocalDate_TimeStamp_LocalTime
Solutions to Chinese garbled code in CMD window
[go practical basis] how to customize and use a middleware in gin
A detailed explanation takes you to reproduce the statistical learning method again -- Chapter 2, perceptron model
BugkuCTF-web16(备份是个好习惯)
Read Day5 30 minutes before going to bed every day_ All key values in the map, how to obtain all value values
JVM instruction mnemonic
TD联合Modelsim进行功能仿真
MySQL error: unblock with mysqladmin flush hosts
别找了,Chrome浏览器必装插件都在这了