Skip to content

ZooKeeper Dynamic Configuration

jon-ruckwood edited this page Nov 19, 2014 · 8 revisions

Configuring ZooKeeperConfigurationSource

  • This implementation requires the path to the ZK root parent node that contains the hierarchy of configuration properties. An example is /[my-app]/config
  • Properties are direct ZK child nodes of the root parent ZK node. An example ZK child property node is /[my-app]/config/com.fluxcapacitor.my.property
  • The value is stored in the ZK child property node and can be updated at any time.
  • All servers will receive a ZK Watcher callback and automatically update their value similar to other dynamic configuration sources (ie. DynamoDB, etc.)
  • Any node created or updated under this node - even dynamically at runtime - will be accessible through the archaius dynamic property framework.

Example Configuration

String zkConfigRootPath = "/[my-app]/config";

CuratorFramework client CuratorFrameworkFactory.newClient(zkConnectionString,
        new ExponentialBackoffRetry(1000, 3));

ZooKeeperConfigurationSource zkConfigSource = new ZooKeeperConfigurationSource(client, zkConfigRootPath);
zkConfigSource.start();

DynamicWatchedConfiguration zkDynamicConfig = new DynamicWatchedConfiguration(zkConfigSource);

ConfigurationManager.install(zkDynamicConfig);

The property value is retrieved from the /[my-app]/config/com.fluxcapacitor.my.property ZK node:

String myProperty = DynamicPropertyFactory.getInstance()
    .getStringProperty("com.fluxcapacitor.my.property", "<none>")
    .get();

Examples in Practice