ConnectionResolver

Helper class used to retrieve component’s connections.

Description

The ConnectionResolver class is used to retrieve a component’s 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 used 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

NewConnectionResolver

Creates a new instance of ConnectionResolver.

NewConnectionResolver(ctx context.Context, config *config.ConfigParams, references refer.IReferences) *ConnectionResolver

NewEmptyConnectionResolver

Creates a new instance of ConnectionResolver.

NewEmptyConnectionResolver() *ConnectionResolver

Methods

Add

Adds a new connection to component connections.

(c *ConnectionResolver) Add(connection *ConnectionParams)

Configure

Configures component by passing configuration parameters.

(c *ConnectionResolver) Configure(ctx context.Context, config *config.ConfigParams)

  • ctx: context.Context - operation context.
  • config: *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 fully fleshed connection use the resolve method instead.

(c *ConnectionResolver) GetAll() []*ConnectionParams

Register

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

(c *ConnectionResolver) Register(correlationId string, connection *ConnectionParams) error

  • correlationId: string - (optional) transaction id used to trace execution through the call chain.
  • connection: *ConnectionParams - connection to a register.
  • returns: error - returned error if not registered.

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.

(c *ConnectionResolver) Resolve(correlationId string) (*ConnectionParams, error)

  • correlationId: string - (optional) transaction id used to trace execution through the call chain.
  • returns: (*ConnectionParams, error) - resolved connection parameters or nil if nothing was found.

ResolveAll

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

(c *ConnectionResolver) ResolveAll(correlationId string) ([]*ConnectionParams, error)

  • correlationId: string - (optional) transaction id used to trace execution through the call chain.
  • returns: ([]*ConnectionParams, error) - list of resolved connections.

SetReferences

Sets references to dependent components.

(c *ConnectionResolver) SetReferences(ctx context.Context, references refer.IReferences)

  • ctx: context.Context - operation context.
  • references: refer.IReferences - references to locate the component dependencies.

Examples

config = NewConfigParamsFromTuples(
	"connection.host", "10.1.1.100",
	"connection.port", 8080,
)
connectionResolver := NewConnectionResolver()
connectionResolver.Configure(context.Background(), config)
connectionResolver.SetReferences(context.Background(), references)
res, err := connectionResolver.Resolve("123")

See also