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 the class.

MemoryDiscovery([ConfigParams? config])

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

Instance methods

configure

Configures a component by passing its configuration parameters.

@override

void configure(ConfigParams config)

  • config: ConfigParams - configuration parameters to be set.

readConnections

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

void readConnections(ConfigParams config)

  • connections: ConfigParams - configuration parameters to be read

register

Registers connection parameters into the discovery service.

@override

Future<ConnectionParams> register(IContext? context, String key, ConnectionParams connection)

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

resolveAll

Resolves all connection parameters by their key.

@override

Future<List<ConnectionParams>> resolveAll(IContext? context, String key)

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

resolveOne

Resolves a single connection parameters by its key.

@override

Future<ConnectionParams?> resolveOne(IContext? context, String key)

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

Examples

var config = ConfigParams.fromTuples(
    'connections.key1.host', '10.1.1.100',
    'connections.key1.port', '8080',
    'connections.key2.host', '10.1.1.100',
    'connections.key2.port', '8082'
);

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

var connection await discovery.resolveOne('123', 'key1');
// Result: host=10.1.1.100;port=8080

See also