Files
helidon/examples/config/changes
2020-10-16 15:37:23 -07:00
..
2018-12-21 16:00:38 -08:00
2020-05-04 12:46:19 -07: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:

  1. ChangesSubscriberExample.java: uses Config.changes to register an application-specific Flow.Subscriber with a config-provided Flow.Publisher to be notified of changes to the underlying configuration source as they occur
  2. OnChangeExample.java: uses Config.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