Implements: IConfigReader, IReconfigurable
Description
The MemoryConfigReader class allows you to create a config reader that stores a configuration in memory.
Configuration parameters
The configuration parameters are the configuration template
- path: path to the configuration file
- parameters: this entire section is used as template parameters
- …
Constructors
Creates a new instance of a config reader.
MemoryConfigReader([ConfigParams? config])
- config: ConfigParams? - (optional) component configuration parameters
Instance methods
addChangeListener
Adds a listener that will be notified when configuration is changed
@override
void addChangeListener(INotifiable listener)
- listener: INotifiable - a listener to be added.
configure
Configures a component by passing its configuration parameters.
@override
void configure(ConfigParams config)
- config: ConfigParams - configuration parameters to be set.
readConfig
Reads a configuration and parameterizes it with given values.
@override
Future<ConfigParams> readConfig(String? correlationId, ConfigParams? parameters)
- correlationId: string - (optional) transaction id used to trace execution through the call chain.
- parameters: ConfigParams? - values to parameters of the configuration or null to skip parameterization.
- returns: Future<ConfigParams> - ConfigParams configuration.
removeChangeListener
Remove a previously added change listener.
@override
void removeChangeListener(INotifiable listener)
- listener: INotifiable - a listener to be removed.
Examples
var config = ConfigParams.fromTuples([
'connection.host', '{{SERVICE_HOST}}',
'connection.port', '{{SERVICE_PORT}}{{^SERVICE_PORT}}8080{{/SERVICE_PORT}}'
]);
var configReader = new MemoryConfigReader();
configReader.configure(config);
var parameters = ConfigParams.fromValue(process.env);
var config = await configReader.readConfig('123', parameters)
// Possible result: connection.host=10.1.1.100;connection.port=8080