当前位置:网站首页>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
边栏推荐
- C语言之判断直角三角形
- Knife4j 2. Solution to the problem of file control without selection when uploading x version files
- Alibaba / popular JSON parsing open source project fastjson2
- 一篇详解带你再次重现《统计学习方法》——第二章、感知机模型
- FragmentTabHost实现房贷计算器界面
- 图像识别-数据增广
- Microservice practice | fuse hytrix initial experience
- AMQ 4043 solution for errors when using IBM MQ remote connection
- 微服务实战|Eureka注册中心及集群搭建
- 上班第一天的报错(AWVS卸载不彻底)
猜你喜欢
kinect dk 获取CV::Mat格式的彩色RGB图像(openpose中使用)
Solution to amq4036 error in remote connection to IBM MQ
TD联合Modelsim进行功能仿真
Navicat remote connection MySQL reports an error 1045 - access denied for user 'root' @ '222.173.220.236' (using password: yes)
定时线程池实现请求合并
Required request body is missing:(跨域问题)
BugkuCTF-web21(详细解题思路及步骤)
Matplotlib swordsman line - first acquaintance with Matplotlib
idea查看字节码配置
Bold prediction: it will become the core player of 5g
随机推荐
Solutions to Chinese garbled code in CMD window
Microservice practice | fuse hytrix initial experience
Thinkphp5 how to determine whether a table exists
Insight into cloud native | microservices and microservice architecture
tinyxml2 读取和修改文件
Chrome browser plug-in fatkun installation and introduction
VIM操作命令大全
每天睡前30分钟阅读Day5_Map中全部Key值,全部Value值获取方式
西瓜书--第五章.神经网络
Number structure (C language) -- Chapter 4, compressed storage of matrices (Part 2)
C语言之分草莓
Failed to configure a DataSource: ‘url‘ attribute is not specified and no embedd
Discussion on improving development quality and reducing test bug rate
QT QLabel样式设置
微服务实战|负载均衡组件及源码分析
MySql报错:unblock with mysqladmin flush-hosts
图像识别-数据采集
因上努力,果上随缘
How to use PHP spoole to implement millisecond scheduled tasks
Chrome视频下载插件–Video Downloader for Chrome