Inherits: 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 this class.
public
MemoryDiscovery(ConfigParams config = null)
- config: ConfigParams - (optional) configuration with connection parameters.
Creates a new instance of this class.
public
MemoryDiscovery()
Instance methods
Configure
Configures a component by passing its configuration parameters.
public virtual
void Configure(ConfigParams config)
- config: ConfigParams - configuration parameters to be set.
ReadConnections
Reads connections from configuration parameters. Each section represents an individual Connection params.
private
void ReadConnections(ConfigParams connections)
- connections: ConfigParams - configuration parameters to be read
RegisterAsync
Registers connection parameters into the discovery service.
public
Task<void> RegisterAsync(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.
ResolveAllAsync
Resolves all connection parameters by their key.
public
Task<List<ConnectionParams>> ResolveAllAsync(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: Task<List<ConnectionParams>> - list with resolved connections.
ResolveOneAsync
Resolves a single connection parameters by its key.
public
Task<ConnectionParams> ResolveOneAsync(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: Task<ConnectionParams> - resolved connection.
Examples
ConfigParams config = ConfigParams.FromTuples(
"key1.host", "10.1.1.100",
"key1.port", "8080",
"key2.host", "10.1.1.101",
"key2.port", "8082"
);
MemoryDiscovery discovery = new MemoryDiscovery();
discovery.Configure(config);
await discovery.resolveOne("123", "key1");
// Result: host=10.1.1.100;port=8080