ConnectionResolver

Helper class used to retrieve component connections.

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 the class.

ConnectionResolver([ConfigParams? config, IReferences? references])

  • config: ConfigParams? - (optional) component’s configuration parameters
  • references: IReferences? - (optional) component’s references

Instance methods

add

Adds a new connection to the object.

void add(ConnectionParams connection)

configure

Configures a component by passing its configuration parameters.

void configure(ConfigParams config)

  • config: ConfigParams - configuration parameters to be set.

getAll

Gets all configured connections. Redirect to Discovery services is not done at this point. If you need fully fleshed connection use resolve method instead.

List<ConnectionParams> getAll()

register

Registers the given connection in all referenced discovery services. This method can be used for dynamic service discovery.

Future<ConnectionParams> register(String? correlationId, ConnectionParams connection)

  • correlationId: String? - (optional) transaction id used to trace execution through the call chain.
  • connection: Future<ConnectionParams> - connection to register.
  • returns: Future<ConnectionParams> - Future that receives registered connection or throws error.

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.

Future<ConnectionParams?> resolve(String? correlationId)

  • correlationId: String? - (optional) transaction id used to trace execution through the call chain.
  • returns: Future<ConnectionParams?> - resolved connection parameters or null if nothing was found.

resolveAll

Resolves all the component’s connections. If the connections are configured to be retrieved from Discovery service it finds a IDiscovery and resolves the connection there.

Future<List<ConnectionParams>> resolveAll(String? correlationId)

  • correlationId: String? - (optional) transaction id used to trace execution through the call chain.
  • returns: Future<List<ConnectionParams>> - list of resolved connections.

setReferences

Sets references to dependent components.

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);
connection await = connectionResolver.resolve('123')
    // Now use connection...

See also