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.
MemoryDiscovery(config: ConfigParams = None)
- config: ConfigParams - (optional) configuration with connection parameters.
Instance methods
configure
Configures component by passing configuration parameters.
configure(config: ConfigParams)
- config: ConfigParams - configuration parameters to be set.
read_connections
Reads connections from configuration parameters. Each section represents an individual Connection params
read_connections(connections: ConfigParams)
- connections: ConfigParams - configuration parameters to be read
register
Registers connection parameters into the discovery service.
register(correlation_id: Optional[str], key: str, connection: ConnectionParams): ConnectionParams
- correlation_id: Optional[str] - (optional) transaction id to trace execution through call chain.
- key: str - a key to uniquely identify the connection parameters.
- connection: ConnectionParams - a connection to be registered.
- returns: ConnectionParams - the registered connection parameters.
resolve_all
Resolves all connection parameters by their key.
resolve_all(correlation_id: Optional[str], key: str): List[ConnectionParams]
- correlation_id: Optional[str] - (optional) transaction id to trace execution through a call chain.
- key: str - a key to uniquely identify the connections.
- returns: List[ConnectionParams] - a list with resolved connections.
resolve_one
Resolves a single connection parameters by its key.
resolve_one(correlation_id: Optional[str], key: str): ConnectionParams
- correlation_id: Optional[str] - (optional) transaction id to trace execution through a call chain.
- key: str - a key to uniquely identify the connection.
- returns: ConnectionParams - a resolved connection.
Examples
config = ConfigParams.from_tuples(
"key1.host", "10.1.1.100",
"key1.port", "8080",
"key2.host", "10.1.1.100",
"key2.port", "8082"
)
discovery = MemoryDiscovery()
discovery.configure(config)
connection = discovery.resolve_one("123", "key1")
# Result: host=10.1.1.100;port=8080