当前位置:网站首页>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
边栏推荐
- 京东面试官问:LEFT JOIN关联表中用ON还是WHERE跟条件有什么区别
- Chrome browser tag management plug-in – onetab
- Flink - use the streaming batch API to count the number of words
- Oracle delete tablespace and user
- 定时线程池实现请求合并
- Double non undergraduate students enter the factory, while I am still quietly climbing trees at the bottom (Part 1)
- 洞见云原生|微服务及微服务架构浅析
- Enterprise level SaaS CRM implementation
- Learn combinelatest through a practical example
- [go practical basis] how to install and use gin
猜你喜欢

定时线程池实现请求合并

Solution to amq4036 error in remote connection to IBM MQ

Flink - use the streaming batch API to count the number of words

【Go实战基础】gin 如何获取 GET 和 POST 的请求参数

Don't look for it. All the necessary plug-ins for Chrome browser are here

Oracle modify database character set

Solutions to Chinese garbled code in CMD window

自定义Redis连接池
![[go practical basis] how to verify request parameters in gin](/img/de/50db131d6993e5d955e3416c667c4c.png)
[go practical basis] how to verify request parameters in gin

十年开发经验的程序员告诉你,你还缺少哪些核心竞争力?
随机推荐
idea查看字节码配置
微服务实战|Eureka注册中心及集群搭建
Watermelon book -- Chapter 5 neural network
Jingdong senior engineer has developed for ten years and compiled "core technology of 100 million traffic website architecture"
The channel cannot be viewed when the queue manager is running
洞见云原生|微服务及微服务架构浅析
概率还不会的快看过来《统计学习方法》——第四章、朴素贝叶斯法
Mathematics in machine learning -- point estimation (I): basic knowledge
聊聊消息队列高性能的秘密——零拷贝技术
In depth analysis of how the JVM executes Hello World
【Go实战基础】gin 如何验证请求参数
Microservice practice | load balancing component and source code analysis
以字节跳动内部 Data Catalog 架构升级为例聊业务系统的性能优化
Matplotlib swordsman line - layout guide and multi map implementation (Updated)
Timed thread pool implements request merging
[go practical basis] how can gin get the request parameters of get and post
Hystrix implements request consolidation
Mysql 多列IN操作
Cloudrev self built cloud disk practice, I said that no one can limit my capacity and speed
破茧|一文说透什么是真正的云原生