Package io.vertx.config
Interface ConfigRetriever
-
public interface ConfigRetriever
Defines a configuration retriever that read configuration fromConfigStore
and tracks changes periodically.- Author:
- Clement Escoffier
-
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Modifier and Type Method Description Future<Void>
close()
Closes the retriever.ReadStream<JsonObject>
configStream()
static ConfigRetriever
create(Vertx vertx)
Creates an instance of the default implementation of theConfigRetriever
, using the default settings (json file, system properties and environment variables).static ConfigRetriever
create(Vertx vertx, ConfigRetrieverOptions options)
Creates an instance of the default implementation of theConfigRetriever
.JsonObject
getCachedConfig()
Gets the last computed configuration.Future<JsonObject>
getConfig()
Reads the configuration from the differentConfigStore
and computes the final configuration.void
listen(Handler<ConfigChange> listener)
Registers a listener receiving configuration changes.ConfigRetriever
setBeforeScanHandler(Handler<Void> handler)
Registers a handler called before every scan.ConfigRetriever
setConfigurationProcessor(java.util.function.Function<JsonObject,JsonObject> processor)
Registers a handler that process the configuration before being injected into#getConfig(Handler)
orlisten(Handler)
.
-
-
-
Method Detail
-
create
static ConfigRetriever create(Vertx vertx, ConfigRetrieverOptions options)
Creates an instance of the default implementation of theConfigRetriever
.- Parameters:
vertx
- the vert.x instanceoptions
- the options, must not benull
, must contain the list of configured store.- Returns:
- the created instance.
-
create
static ConfigRetriever create(Vertx vertx)
Creates an instance of the default implementation of theConfigRetriever
, using the default settings (json file, system properties and environment variables).- Parameters:
vertx
- the vert.x instance- Returns:
- the created instance.
-
getConfig
Future<JsonObject> getConfig()
Reads the configuration from the differentConfigStore
and computes the final configuration.- Returns:
- a future notified the computed configuration, or a failure if the configuration cannot be retrieved
-
getCachedConfig
JsonObject getCachedConfig()
Gets the last computed configuration.- Returns:
- the last configuration
-
listen
void listen(Handler<ConfigChange> listener)
Registers a listener receiving configuration changes. This method cannot only be called if the configuration is broadcasted.- Parameters:
listener
- the listener
-
setBeforeScanHandler
ConfigRetriever setBeforeScanHandler(Handler<Void> handler)
Registers a handler called before every scan. This method is mostly used for logging purpose.- Parameters:
handler
- the handler, must not benull
- Returns:
- the current config retriever
-
setConfigurationProcessor
ConfigRetriever setConfigurationProcessor(java.util.function.Function<JsonObject,JsonObject> processor)
Registers a handler that process the configuration before being injected into#getConfig(Handler)
orlisten(Handler)
. This allows the code to customize the configuration.- Parameters:
processor
- the processor, must not benull
. The method must not returnnull
. The returned configuration is used. If the processor does not update the configuration, it must return the input configuration. If the processor throws an exception, the failure is passed to the#getConfig(Handler)
handler.- Returns:
- the current config retriever
-
configStream
ReadStream<JsonObject> configStream()
- Returns:
- the stream of configurations. It's single stream (unicast) and that delivers the last known config and the successors periodically.
-
-