HttpConnectionResolver

Helper class to retrieve connections for HTTP-based services and clients.

Description

The HttpConnectionResolver class is used to retrieve connections for HTTP-based services and clients.

Important points

  • In addition to its regular functions, ConnectionResolver is able to parse http:// URIs and validate connection parameters before returning them.

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 params N]: Nth connection parameters

References

  • *:discovery:*:*:1.0 - (optional) IDiscovery services to resolve a connection

Constructors

NewHttpConnectionResolver

NewHttpConnectionResolver creates new instance NewHttpConnectionResolver

NewHttpConnectionResolver() *HttpConnectionResolver

Fields

ConnectionResolver

Creates a connection resolver.

ConnectionResolver: ConnectionResolver

CredentialResolver

The base credential resolver.

CredentialResolver: CredentialResolver

Methods

Configure

Configures component by passing configuration parameters.

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

  • ctx: context.Context - operation context.
  • config: *cconf.ConfigParams - configuration parameters to be set.

Register

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

(c *HttpConnectionResolver) Register(correlationId string) error

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

Resolve

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

(c *HttpConnectionResolver) Resolve(correlationId string) (connection *ccon.ConnectionParams, credential *cauth.CredentialParams, err error)

  • correlationId: string - (optional) transaction id used to trace execution through the call chain.
  • returns: (connection *ccon.ConnectionParams, credential *cauth.CredentialParams, err error) - resolved connection and credential or error.

ResolveAll

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

(c *HttpConnectionResolver) ResolveAll(correlationId string) (connections []*ccon.ConnectionParams, credential *cauth.CredentialParams, err error)

SetReferences

Sets references to dependent components.

(c *HttpConnectionResolver) SetReferences(ctx context.Context, references crefer.IReferences)

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

Examples

config := cconf.NewConfigParamsFromTuples(
	"connection.host", "10.1.1.100",
	"connection.port", 8080,
)

connectionResolver = NewHttpConnectionResolver()
connectionResolver.Configure(context.Background(), config)
connectionResolver.SetReferences(context.Background(), references)

connection, err := connectionResolver.Resolve("123")
// Now use connection...

See also