Description
The ConnectionResolver class is used to retrieve component connections.
Important points
- If the connections are configured to be retrieved from IDiscovery, the connection resolver will automatically locate IDiscovery in component references and retrieve the connections from there using the discovery_key parameter.
Configuration parameters
connection:
- discovery_key: (optional) a key to retrieve the connection from IDiscovery
- … : other connection parameters
connections: alternative to connection
- [connection params 1]: first connection parameters
- … : connection parameters for key 1
- [connection params N]: Nth connection parameters
- … : connection parameters for key N
References
- *:discovery:*:*:1.0 - (optional) IDiscovery services to resolve connections
Constructors
Creates a new instance of connection resolver.
ConnectionResolver(config: ConfigParams = None, references: IReferences = None)
- config: ConfigParams - (optional) component configuration parameters
- references: IReferences - (optional) component references
Instance methods
add
Adds a new connection to component connections
add(connection: ConnectionParams)
- connection: ConnectionParams - new connection parameters to be added
configure
Configures component by passing configuration parameters.
configure(config: ConfigParams)
- config: ConfigParams - configuration parameters to be set.
get_all
Gets all connections configured in component configuration. Redirect to Discovery services is not done at this point. If you need fully fleshed connection use resolve method instead.
get_all(): List[ConnectionParams]
- returns: List[ConnectionParams] - a list with connection parameters
register
Registers the given connection in all referenced discovery services. This method can be used for dynamic service discovery.
register(correlation_id: Optional[str], connection: ConnectionParams)
- correlation_id: Optional[str] - (optional) transaction id to trace execution through call chain.
- connection: ConnectionParams - a connection to register.
resolve
Resolves a single component connection. If connections are configured to be retrieved from Discovery service it finds a IDiscovery and resolves the connection there.
resolve(correlation_id: Optional[str]): Optional[ConnectionParams]
- correlation_id: Optional[str] - (optional) transaction id to trace execution through call chain.
- returns: Optional[ConnectionParams] - resolved connection parameters or None if nothing was found.
resolve_all
Resolves all component connection. If connections are configured to be retrieved from Discovery service it finds a IDiscovery and resolves the connection there.
resolve_all(correlation_id: Optional[str]): List[ConnectionParams]
- correlation_id: Optional[str] - (optional) transaction id to trace execution through call chain.
- returns: List[ConnectionParams] - a list of resolved connections.
set_references
Sets references to dependent components.
set_references(references: IReferences)
- references: IReferences - references to locate the component dependencies.
Examples
config = ConfigParams.from_tuples("connection.host", "10.1.1.100", "connection.port", 8080)
connectionResolver = ConnectionResolver()
connectionResolver.configure(config)
connectionResolver.set_references(references)
connectionResolver.resolve("123")