- JAVA 6+
- TOMCAT 7+
- EasyZk - 封装应用到zookeeper的属性配置的获取及更新
- ConfigWeb - 提供web界面维护属性配置,提供配置导入导出功能
- 集中管理集群配置
- 实现配置热更新
- Spring集成
- 本地配置覆盖
- 配置管理web界面
- ConfigFactory - 配置工厂,用于定义zookeeper地址及配置根目录
- ConfigNode - 配置组,一组配置信息,对应于遗留系统中的properties属性文件
- maven
<dependency>
<groupId>com.dangdang</groupId>
<artifactId>config-toolkit-easyzk</artifactId>
<version>1.2.0-RELEASE</version>
</dependency>
- 直接使用
// 创建配置工厂指向zk的地址及配置在zk中的根地址,映射到zookeeper中的/projectx/modulex
ConfigFactory configFactory = new ConfigFactory("zoo.host1:8181,zoo.host2:8181,zoo.host3:8181", "/projectx/modulex");
// 从工厂中加载某配置组,映射到zookeeper中的/projectx/modulex/group0
ConfigNode node = configFactory.getConfigNode("group0");
// 从配置组中获取某配置,映射到zookeeper中的/projectx/modulex/group0/name
Assert.assertNotNull(node.getProperty("name"));
- Spring PlaceholderConfigurer集成
<bean id="configFactory" class="com.dangdang.config.service.easyzk.ConfigFactory" factory-method="create">
<constructor-arg name="connectStr" value="zoo.host1:8181,zoo.host2:8181,zoo.host3:8181" />
<constructor-arg name="rootNode" value="/projectx/modulex" />
</bean>
<bean id="zookeeperSources" class="com.dangdang.config.service.easyzk.support.spring.ZookeeperSourceFactory" factory-method="create">
<constructor-arg name="configFactory" ref="configFactory" />
<constructor-arg name="nodes">
<list>
<value>config-group1</value>
<value>config-group2</value>
<value>config-group3</value>
</list>
</constructor-arg>
</bean>
<bean class="org.springframework.context.support.PropertySourcesPlaceholderConfigurer">
<property name="order" value="1" />
<property name="ignoreUnresolvablePlaceholders" value="true" />
<property name="propertySources" ref="zookeeperSources" />
</bean>
- 本地配置覆盖(一般用于调试集群中的单点)
在classpath下添加本地配置文件,格式为XML,默认为local-override.xml,可以通过指定环境变量来修改
-Dlocal-override.file=yourfile.xml
[例]:
<?xml version="1.0" encoding="UTF-8"?>
<node-factories xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://crnlmchina.github.io/local-override.xsd">
<node-factory root="/projectx/modulex">
<group id="property-group1">
<node key="string_property_key">Welcome here.</node>
</group>
</node-factory>
</node-factories>
以上的配置会覆盖zookeeper中/projectx/modulex/property-group1/string_property_key
的值为Welcome here.