Rhea is a type-safe dynamic configuration library for JVM applications. This library uses asynchronous data flows that gives a natural auto-reloading feature in runtime, so it allows to change configuration properties and get the freshest values in your application without the need to restart.
- Open source project under the MIT License
- Extendable with user-defined property types
- Extendable with user-defined configuration sources
- Supports reading configuration from files (.yaml, .properties, .json), Vault, JDBC, MongoDB
To get started, add uk.dsxt:rhea-core:<version>
as a dependency:
dependencies {
compile group: "uk.dsxt", name:"rhea-core", version: "0.0.1-SNAPSHOT"
}
<dependencies>
<dependency>
<groupId>uk.dsxt</groupId>
<artifactId>rhea-core</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
</dependencies>
To read configuration from source other than .properties, add its rhea module as a dependency. For example, to add .json as configuration source:
dependencies {
...
compile group: "uk.dsxt", name:"rhea-json", version: "0.0.1-SNAPSHOT"
}
<dependencies>
...
<dependency>
<groupId>uk.dsxt</groupId>
<artifactId>rhea-json</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
</dependencies>
Note: If configuration source is not supported, you can add it by implementing ConfigSource interface.
-
Build a configuration object that holds properties, add configuration sources
ConfigSource jsonSource = new JsonConfigSource(Paths.get("src" + File.separator + "test" + File.separator + "resources"), "jsonSource.json"); ReactiveConfig config = new ReactiveConfig.Builder() .addSource("jsonConfig", jsonSource) .build();
-
Create reloadable properties
Reloadable<Boolean> isSomethingOn = config.get("flag", PropertyTypesKt.booleanType); Reloadable<Integer> port = config.get("port", PropertyTypesKt.intType); // access the freshest typed values with get() Server server = new Server(port.get(), "host"); if (isSomethingOn.get()) { server.start(); }
-
Also, you can add some complex logic that will execute every time the property is changed
port.onChange((Integer newValue) -> { // for example, restart server });
-
Build a configuration object that holds properties, add configuration sources
val jsonSource: ConfigSource = JsonConfigSource(Paths.get("src" + File.separator + "test" + File.separator + "resources"), "jsonSource.json") val config: ReactiveConfig = ReactiveConfig.Builder() .addSource("jsonConfig", jsonSource) .build()
-
Create reloadable properties or declare objects that extend PropertyGroup to define hierarchies of properties
val isSomethingOn: Realoadable<Boolean> = config["flag", booleanType] object server : PropertyGroup() { val name by stringType val port by intType } // access the freshest typed values with get() val server = Server(config[server.port].get(), config[server.name].get()) if (isSomethingOn.get()) { server.start() }
-
Also, you can add some complex logic that will execute every time the property is changed
val port: Reloadable<Int> = config[server.port] port.onChange() { // for example, restart server }
To add a custom property type, you should create an instance of PropertyType class and provide it with default property value and parse function.
To support a new configuration source, you should implement ConfigSource interface.
- Dmitry Vologin - GitHub account
- Alexandra Osipova - GitHub account
- Anton Plotnikov - GitHub account
- Philipp Dolgolev - GitHub account
This project is licensed under the MIT License. The full text could be found in LICENSE.md.
- Inspired by Tinkoff ReactiveConfig and Konfig
- Rhea is one of the Titans in Greek mythology, the mother of the first generation of the Olympian gods
- Rhea's name is believed to be derived from the word ῥέω (rheo), meaning “flow” or “ease”