protoconf-java is the java sdk for protoconf .
Java 8 or above is required.
Add dependency to pom.xml
<dependency>
<groupId>com.yoozoo.protoconf</groupId>
<artifactId>protoconf-java</artifactId>
<version>${protoconf-java-version}</version>
</dependency>
// set app token
String appToken = "U2FsdGVkX1+EGNROfb41wAhtOumHKQPkli1FEL54C/U=";
EtcdReader etcdReader = new EtcdReader();
etcdReader.setAppToken(appToken);
// connect to etcd
ConfigurationReader configurationReader = new ConfigurationReader(etcdReader);
// fill in etcd values to config instance
configurationReader.config(Configuration.instance());
// watch config changes
Configuration.instance().watch_name(new ChangeListener() {
@Override
public void onChange(String newValue) {
System.out.println("name has been changed to: " + newValue);
}
});
configurationReader.watchKeys(Configuration.instance());
// get config value
dataSource.setUrl(Configuration.instance().get_mysqlDsn());
dataSource.setUsername(Configuration.instance().get_username());
dataSource.setPassword(Configuration.instance().get_password());
protoconf-java is under the Apache 2.0 license. See the LICENSE file for details.