Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

get config from zookeeper #81

Closed
ksaritek opened this issue Jun 16, 2014 · 4 comments
Closed

get config from zookeeper #81

ksaritek opened this issue Jun 16, 2014 · 4 comments

Comments

@ksaritek
Copy link
Contributor

is there a possibilty to create config from zookeeper instead of file on classpath?

@lviggiano
Copy link
Collaborator

I didn't know about Zookeeper. OWNER is able to load configuration from standard URLs, which includes "file:", "ftp:", "http[s]:" etc.
If zookeeper supports exposing its configuration via an URL this might work. Otherwise we need to add a "zookeeper:" URL as we did for "classpath:". I got a push request to use URI instead of URL recently that may be part of this implementation, since "zookeeper:" URL may throw an exception if used in the constructor of a URL, while should be valid for URI.
OWNER defines an method called Factory.registerLoader() and a Loader Interface, to allow users to define new kind of loaders, i.e. a ZookeperLoader object.

@lviggiano
Copy link
Collaborator

Hi.

I just pushed on master some code to get zookeeper configuration.

It doesn't support the hot reload mechanism yet, but I hope it will in future (no schedule for this yet).

See ZooKeeperLoaderTest.java unit test as example.

There are three steps you need to do:

// 1st step: define the ZooKeeperConfig class:

@Sources("zookeeper://127.0.0.1:65403/test")
public static interface ZooKeeperConfig extends Config {
    String thanks();
    List<String> greetings();
    String notAvailable();
}

// 2nd step: register a loader to handle the "zookeeper://" URL: 

ConfigFactory.registerLoader(new ZooKeeperLoader());

// 3rd step: use things as usual.

ZooKeeperConfig cfg = ConfigFactor.create(ZooKeeperConfig.class);

@ksaritek
Copy link
Contributor Author

ksaritek commented Oct 2, 2014

Thanks for help, that was my firts pull request :)

On Thu, Oct 2, 2014 at 2:12 AM, Luigi R. Viggiano notifications@github.com
wrote:

Hi.

I just pushed on master some code to get zookeeper configuration. It
doesn't support the hot reload mechanism yet, but I hope it will in future
(no schedule for this yet).

See ZooKeeperLoaderTest.java
https://github.com/lviggiano/owner/blob/master/owner-loaders/src/test/java/org/aeonbits/owner/loaders/ZooKeeperLoaderTest.java
unit test as example.

There are two steps you need to do:

// 1st step: define the ZooKeeperConfig class:

@sources("zookeeper://127.0.0.1:65403/test")
public static interface ZooKeeperConfig extends Config {
String thanks();
List greetings();
String notAvailable();
}
// 2nd step: register a loader to handle the "zookeeper://" URL: ConfigFactory.registerLoader(new ZooKeeperLoader());
// 3rd use things as usual.
ZooKeeperConfig cfg = ConfigFactor.create(ZooKeeperConfig.class);


Reply to this email directly or view it on GitHub
#81 (comment).

@lviggiano
Copy link
Collaborator

Cool thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants