当前位置:网站首页>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
边栏推荐
- 数构(C语言)——第四章、矩阵的压缩存储(下)
- Solutions to Chinese garbled code in CMD window
- 【Go实战基础】gin 如何验证请求参数
- 别找了,Chrome浏览器必装插件都在这了
- Long summary (code with comments) number structure (C language) -- Chapter 4, string (Part 1)
- 微服务实战|Eureka注册中心及集群搭建
- 长篇总结(代码有注释)数构(C语言)——第四章、串(上)
- Microservice practice | declarative service invocation openfeign practice
- 远程连接IBM MQ报错AMQ4036解决方法
- Discussion on improving development quality and reducing test bug rate
猜你喜欢
C4D quick start tutorial - C4d mapping
Idea view bytecode configuration
Matplotlib剑客行——容纳百川的艺术家教程
告别996,IDEA中必装插件有哪些?
From concept to method, the statistical learning method -- Chapter 3, k-nearest neighbor method
Timed thread pool implements request merging
概率还不会的快看过来《统计学习方法》——第四章、朴素贝叶斯法
Cloudrev self built cloud disk practice, I said that no one can limit my capacity and speed
远程连接IBM MQ报错AMQ4036解决方法
【Go实战基础】gin 如何自定义和使用一个中间件
随机推荐
以字节跳动内部 Data Catalog 架构升级为例聊业务系统的性能优化
Number structure (C language) -- Chapter 4, compressed storage of matrices (Part 2)
Chrome browser plug-in fatkun installation and introduction
分布式锁的这三种实现方式,如何在效率和正确性之间选择?
Programmers with ten years of development experience tell you, what core competitiveness do you lack?
盘点典型错误之TypeError: X() got multiple values for argument ‘Y‘
MySql报错:unblock with mysqladmin flush-hosts
oracle修改数据库字符集
Don't look for it. All the necessary plug-ins for Chrome browser are here
使用IBM MQ远程连接时报错AMQ 4043解决思路
Enterprise level SaaS CRM implementation
Micro service practice | introduction and practice of zuul, a micro service gateway
破茧|一文说透什么是真正的云原生
深入剖析JVM是如何执行Hello World的
Attributes of classfile
Safety production early warning system software - Download safety production app software
Elastic Stack之Beats(Filebeat、Metricbeat)、Kibana、Logstash教程
CSDN Q & A_ Evaluation
Redis sorted set data type API and application scenario analysis
Matplotlib swordsman Tour - an artist tutorial to accommodate all rivers