MemoryConfigReader

Config reader that stores a configuration in memory.

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.

public constructor(config: ConfigParams = null)

  • config: ConfigParams - (optional) component configuration parameters

Instance methods

addChangeListener

Adds a listener that will be notified when configuration is changed

public addChangeListener(listener: INotifiable): void

configure

Configures a component by passing its configuration parameters.

public configure(config: ConfigParams): void

  • config: ConfigParams - configuration parameters to be set.

readConfig

Reads a configuration and parameterizes it with given values.

public readConfig(correlationId: string, parameters: ConfigParams): ConfigParams

  • correlationId: string - (optional) transaction id to trace execution through a call chain.
  • parameters: ConfigParams - values to parameters the configuration or null to skip parameterization.
  • returns: ConfigParams - ConfigParams configuration.

removeChangeListener

Remove a previously added change listener.

public removeChangeListener(listener: INotifiable): void

Examples

let config = ConfigParams.fromTuples(
    "connection.host", "{{SERVICE_HOST}}",
    "connection.port", "{{SERVICE_PORT}}{{^SERVICE_PORT}}8080{{/SERVICE_PORT}}"
);
    
let configReader = new MemoryConfigReader();
configReader.configure(config);
    
let parameters = ConfigParams.fromValue(process.env);
    
let config = await configReader.readConfig("123", parameters);
// Possible result: connection.host=10.1.1.100;connection.port=8080