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) 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 this class.
public
ConnectionResolver(ConfigParams config = null, IReferences references = null)
- config: ConfigParams - (optional) component’s configuration parameters
- references: IReferences - (optional) component’s references
Instance methods
Add
Adds a new connection.
public
void Add(ConnectionParams connection)
- connection: ConnectionParams - new connection parameters to be added
Configure
Configures the component by passing its configuration parameters.
public
void Configure(config: ConfigParams)
- config: ConfigParams - configuration parameters to be set.
GetAll
Gets all connections configured in component configuration. Redirect to Discovery services is not done at this point. If you need a fully fleshed connection, use Resolve method instead.
public
List<ConnectionParams> GetAll()
- returns: List<ConnectionParams> - list with connection parameters
RegisterAsync
Registers the given connection in all referenced discovery services. This method can be used for dynamic service discovery.
public
Task<void> RegisterAsync(string correlationId, ConnectionParams connection)
- correlationId: string - (optional) transaction id used to trace execution through the call chain.
- connection: ConnectionParams - connection to register.
ResolveAsync
Resolves a single component connection. If connections are configured to be retrieved from Discovery service, it finds a IDiscovery and resolves the connection there.
public
Task<ConnectionParams> ResolveAsync(string correlationId)
- correlationId: string - (optional) transaction id used to trace execution through the call chain.
- returns: Task<ConnectionParams> - resolved connection parameters or null if nothing was found.
ResolveAllAsync
Resolves all component connection. If connections are configured to be retrieved from Discovery service, it finds a IDiscovery and resolves the connection there.
public
Task<List<ConnectionParams>> ResolveAllAsync(string correlationId)
- correlationId: string - (optional) transaction id used to trace execution through the call chain.
- returns: Task<List<ConnectionParams>> - list of resolved connections.
SetReferences
Sets references to dependent components.
public
void SetReferences(IReferences references)
- references: IReferences - references to locate the component’s dependencies.
Examples
var config = ConfigParams.FromTuples(
"connection.host", "10.1.1.100",
"connection.port", 8080
);
var connectionResolver = new ConnectionResolver();
connectionResolver.Configure(config);
connectionResolver.SetReferences(references);
connectionResolver.ResolveAsync("123");