当前位置:网站首页>zk配置中心---Config Toolkit配置与使用
zk配置中心---Config Toolkit配置与使用
2022-07-02 06:34:00 【niceyz】
Config Toolkit 简介:用于分布式系统中的资源配置中心,替代传统properties文件,优点:立即修改配置立即生效,不需要新重新打包部署项目。
下载地址:https://github.com/dangdangdotcom/config-toolkit
配置zk,生产环境一般配置5台,创建配置节点时会同步,这里使用默认配置,启动zkServer。
启动项目(将config-face打包成jar或者war部署到服务器,随意):
输入http://localhost:8080 进入登录页面:
创建节点及密码,默认根节点密码使用sha1加密,创建密码方法,(密码:abc):
[[email protected] ~]# python -c "import hashlib;print hashlib.sha1('abc').hexdigest();"
a9993e364706816aba3e25717850c26c9cd0d89d
创建节点:
1. 使用zk客户端
create /projectx 1
create /projectx/modulex a9993e364706816aba3e25717850c26c9cd0d89d
2.使用java代码
<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超时时间;1000 连接超时时间
ZkClient zkClient = new ZkClient("127.0.0.1:2181", 60000, 10000);
// 节点(路径);值;节点类型 PERSISTENT永久节点
//zkClient.create("/projectx","1", CreateMode.PERSISTENT);
zkClient.create("/projectx/modulex","a9993e364706816aba3e25717850c26c9cd0d89d", CreateMode.PERSISTENT);
zkClient.close();
System.out.println("###注册成功###");
}
}
使用节点名:“/projectx/modulex”,密码:“abc”登录,登录后,点击new 创建版本1.0.0
分别创建组,创建节点
使用配置:
1.代码直接获取配置:
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注入配置
<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>
对应zk节点:
https://github.com/dangdangdotcom/config-toolkit
边栏推荐
- There is a problem with MySQL installation (the service already exists)
- Troubleshooting and handling of an online problem caused by redis zadd
- Timed thread pool implements request merging
- 西瓜书--第六章.支持向量机(SVM)
- Talk about the secret of high performance of message queue -- zero copy technology
- 「面试高频题」难度大 1.5/5,经典「前缀和 + 二分」运用题
- Enterprise level SaaS CRM implementation
- 概率还不会的快看过来《统计学习方法》——第四章、朴素贝叶斯法
- Statistical learning methods - Chapter 5, decision tree model and learning (Part 1)
- Long summary (code with comments) number structure (C language) -- Chapter 4, string (Part 1)
猜你喜欢
Elastic Stack之Beats(Filebeat、Metricbeat)、Kibana、Logstash教程
Matplotlib swordsman - a stylist who can draw without tools and code
Troubleshooting and handling of an online problem caused by redis zadd
Don't look for it. All the necessary plug-ins for Chrome browser are here
西瓜书--第六章.支持向量机(SVM)
Win10 uses docker to pull the redis image and reports an error read only file system: unknown
自定義Redis連接池
[go practical basis] how to set the route in gin
There is a problem with MySQL installation (the service already exists)
[go practical basis] how to verify request parameters in gin
随机推荐
我服了,MySQL表500W行,居然有人不做分区?
JVM instruction mnemonic
Customize redis connection pool
Redis sorted set data type API and application scenario analysis
Insight into cloud native | microservices and microservice architecture
【Go实战基础】gin 如何绑定与使用 url 参数
Elastic Stack之Beats(Filebeat、Metricbeat)、Kibana、Logstash教程
oracle修改数据库字符集
Chrome video download Plug-in – video downloader for Chrome
Probability is not yet. Look at statistical learning methods -- Chapter 4, naive Bayesian method
盘点典型错误之TypeError: X() got multiple values for argument ‘Y‘
Flink-使用流批一体API统计单词数量
[go practical basis] gin efficient artifact, how to bind parameters to structures
Matplotlib剑客行——容纳百川的艺术家教程
概率还不会的快看过来《统计学习方法》——第四章、朴素贝叶斯法
Microservice practice | declarative service invocation openfeign practice
Knowledge points are very detailed (code is annotated) number structure (C language) -- Chapter 3, stack and queue
Jingdong senior engineer has developed for ten years and compiled "core technology of 100 million traffic website architecture"
Bold prediction: it will become the core player of 5g
There is a problem with MySQL installation (the service already exists)