Skip to content

boundary/archaius-consul

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

archaius-consul

A consul-backed configuration source for Archaius

Basic Usage:

// setup a consul client ( see https://github.com/Ecwid/consul-api for more info)
final ConsulClient client = new ConsulClient("localhost");

final String rootPath = "my-app/config"; // values will correspond to consul values stored at /v1/kv/my-app/config

// create and start the configuration source
final ConsulWatchedConfigurationSource configSource = new ConsulWatchedConfigurationSource(rootPath, client);
configSource.startAsync();

// register the configuration source with archaius

ConcurrentCompositeConfiguration finalConfig = new ConcurrentCompositeConfiguration();
finalConfig.addConfiguration(new DynamicWatchedConfiguration(configSource), "consul-dynamic");

// install / configure other archaius sources as needed

 ConfigurationManager.install(finalConfig);

registering callbacks

To register a callback on the "example" property, an integer with default value of 2:

final DynamicIntProperty example = DynamicPropertyFactory.getInstance().getIntProperty("example", 2);
example.addCallback(new Runnable() {
    @Override
    public void run() {
        System.out.println("example changed: " + example.get());
    }
});

Now you should be able to see watched callbacks in action by updating the corresponding configuration variable:

curl -X PUT -d `date +%s` localhost:8500/v1/kv/my-app/config/example

About

A consul-backed configuration source for Archaius

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages