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
MemoryDiscovery(ConfigParams config)
- config: ConfigParams - configuration parameters to be set.
readConnections
Reads connections from configuration parameters. Each section represents an individual Connection params
public
void readConnections(ConfigParams config)
- connections: ConfigParams - configuration parameters to be read
register
Registers connection parameters into the discovery service.
public
void register(IContext context, String key, ConnectionParams connection)
- 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.
resolveAll
Resolves all connection parameters by their key.
public
List<ConnectionParams> resolveAll(IContext context, String key)
- context: IContext - (optional) a context to trace execution through call chain.
- key: String - a key to uniquely identify the connections.
- returns: List<ConnectionParams> - a list with resolved connections.
resolveOne
Resolves a single connection parameters by its key.
public
ConnectionParams resolveOne(IContext context, String key)
- context: IContext - (optional) a context to trace execution through call chain.
- key: String - a key to uniquely identify the connection.
- returns: ConnectionParams - a resolved connection.
Examples
{
ConfigParams config = ConfigParams.fromTuples(
"key1.host", "10.1.1.100",
"key1.port", "8080",
"key2.host", "10.1.1.100",
"key2.port", "8082"
);
MemoryDiscovery discovery = new MemoryDiscovery();
discovery.readConnections(config);
discovery.resolve("123", "key1");
}