Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/scalecube/scalecube-config

ScaleCube Config is a configuration access management library for JVM based distributed applications
https://github.com/scalecube/scalecube-config

configuration configuration-registry distributed java jvm

Last synced: 3 months ago
JSON representation

ScaleCube Config is a configuration access management library for JVM based distributed applications

Awesome Lists containing this project

README

        

# ScaleCube Config

[![Maven Central](https://maven-badges.herokuapp.com/maven-central/io.scalecube/config/badge.svg)](https://maven-badges.herokuapp.com/maven-central/io.scalecube/config)

ScaleCube Config is a configuration management library for JVM based distributed applications.

It provides the following functionality:
* Dynamic typed properties
* Register callbacks on property changes
* Object binding for grouping properties
* Extensible range of supported property sources (environment variables, program arguments, classpath, property files, mongodb, git repository, zookeeper etc.)
* Support centralized hierarchical property sources
* Control over order of applying different property sources
* Audit log of property changes
* Expose properties and settings via JMX and/or HTTP

## Usage

Configure and create configuration registry instance:

``` java
Predicate predicate = path -> path.toString().endsWith(".props"); // match by .props extension
ConfigRegistrySettings settings = ConfigRegistrySettings.builder()
.addLastSource("classpath", new ClassPathConfigSource(predicate))
.addLastSource("configDirectory", new DirectoryConfigSource("conf" /* base path */, predicate))
.addListener(new Slf4JConfigEventListener()) // print all property changes to log
.build();
ConfigRegistry configRegistry = ConfigRegistry.create(settings);
```

Get dynamic typed configuration property:

``` java
LongConfigProperty timeoutProperty = configRegistry.longProperty("http.request-timeout");
long timeout = timeoutProperty.get(30 /* default value */);
```

Register callbacks on property modifications:

``` java
timeoutProperty.addCallback((oldValue, newValue) ->
System.out.println("Timeout value changed to " + newValue));
```

Register validators on property values (only values which passed all validators will be applied):
``` java
timeoutProperty.addValidator(val -> val >= 0); // timeout can't be negative
```

Utilize object binding:

``` java
// Define configuration class
public interface MyConfig {
private boolean meaning;
private int answer;
private double realAnswer;
...
}

// myapp.config.meaning=true
// myapp.config.answer=42
// myapp.config.realAnswer=42.000000000000001
ObjectConfigProperty config = configRegistry.objectProperty("myapp.config", MyConfig.class);

// Get current config values
MyConfig currentConfig = config.value(MyConfig.defaultValue() /* or default */);

// Register callback (called only once per config reload even when several properties changed)
config.addCallback((oldConfig, newConfig) ->
System.out.println("MyConfig updated from " + oldConfig + " to " + newConfig));

// Register validator
// If meaning is present, an answer should be at least as big as the answer
config.addValidator(val -> val.meaning && val.answer >= 42);
```

Start embedded HTTP server which exposes configuration endpoints:

``` java
ConfigRegistryHttpServer.create(configRegistry, 5050); // starts http server on port 5050
```

After HTTP server is started explore configuration registry by browsing following endpoints:
* [http://localhost:5050/_config/properties](http://localhost:5050/_config/properties)
* [http://localhost:5050/_config/sources](http://localhost:5050/_config/sources)
* [http://localhost:5050/_config/events](http://localhost:5050/_config/events)
* [http://localhost:5050/_config/settings](http://localhost:5050/_config/settings)

See more examples at [config-examples](https://github.com/scalecube/scalecube-config/tree/master/config-examples/src/main/java/io/scalecube/config/examples) module.

## Maven

Binaries and dependency information for Maven can be found at
[http://search.maven.org](http://search.maven.org/#search%7Cga%7C1%7Cio.scalecube.config).

Change history and [version numbers](http://semver.org/) can be found at [CHANGES.md](https://github.com/scalecube/scalecube-config/blob/master/CHANGES.md).

Maven dependency:

``` xml

io.scalecube
config
x.y.z

io.scalecube
config-http-server
x.y.z

io.scalecube
config-mongo
x.y.z

```

## Bugs and Feedback

For bugs, questions and discussions please use the [GitHub Issues](https://github.com/scalecube/scalecube-config/issues).

## License

[Apache License, Version 2.0](https://github.com/scalecube/scalecube-config/blob/master/LICENSE.txt)