mirror of
https://github.com/jlengrand/helidon.git
synced 2026-03-10 08:21:17 +00:00
Helidon Config Changes Example
This example shows how an application can deal with changes to configuration.
Change notification
The example highlights two approaches to change notification:
ChangesSubscriberExample.java: usesConfig.changesto register an application-specificFlow.Subscriberwith a config-providedFlow.Publisherto be notified of changes to the underlying configuration source as they occurOnChangeExample.java: usesConfig.onChange, passing either a method reference (a lambda expression would also work) which the config system invokes when the config source changes )
Latest-value supplier
A third example illustrates a different solution.
Recall that once your application obtains a Config instance, its config values
do not change. The
AsSupplierExample.java
example shows how your application can get a config supplier that always reports
the latest config value for a key, including any changes made after your
application obtained the Config object. Although this approach does not notify
your application when changes occur, it does permit your code to always use
the most up-to-date value. Sometimes that is all you need.
Build and run
mvn package
java -jar target/helidon-examples-config-changes.jar