MemoryDiscovery

Discovery service that keeps connections in memory.

Implements: IDiscovery, IReconfigurable

Description

The MemoryDiscovery class allows you to create discovery services that keep connections in memory.

Configuration parameters

  • [connection key 1]:
  • : connection parameters for key 1
  • [connection key 2]:
  • : connection parameters for key N

Constructors

Creates a new instance of discovery service.

public constructor(config: ConfigParams = null)

  • config: ConfigParams - (optional) configuration with connection parameters.

Instance methods

configure

Configures component by passing configuration parameters.

public configure(config: ConfigParams): void

  • config: ConfigParams - configuration parameters to be set.

readConnections

Reads connections from configuration parameters. Each section represents an individual Connection params

public readConnections(connections: ConfigParams): void

  • connections: ConfigParams - configuration parameters to be read

register

Registers connection parameters into the discovery service.

public register(context: IContext, key: string, connection: ConnectionParams): Promise<ConnectionParams>

  • context: IContext - (optional) a context to trace execution through call chain.
  • key: string - a key to uniquely identify the connection parameters.
  • connection: ConnectionParams - a connection to be registered.
  • returns: Promise<ConnectionParams> - the registered connection parameters.

resolveAll

Resolves all connection parameters by their key.

public resolveAll(context: IContext, key: string): Promise<ConnectionParams[]>

  • context: IContext - (optional) a context to trace execution through call chain.
  • key: string - a key to uniquely identify the connections.
  • returns: Promise<ConnectionParams[]> - a list with resolved connections.

resolveOne

Resolves a single connection parameters by its key.

public resolveOne(context: IContext, key: string): Promise<ConnectionParams>

  • context: IContext - (optional) a context to trace execution through call chain.
  • key: string - a key to uniquely identify the connection.
  • returns: Promise<ConnectionParams> - a resolved connection.

Examples

let config = ConfigParams.fromTuples(
    "key1.host", "10.1.1.100",
    "key1.port", "8080",
    "key2.host", "10.1.1.101",
    "key2.port", "8082"
);

let discovery = new MemoryDiscovery();
discovery.configure(config);

let connection = await discovery.resolveOne(new Context(), "key1");
// Result: host=10.1.1.100;port=8080

See also