MemoryDiscovery

Discovery service that keeps connections in memory.

Implements: IDiscovery, IReconfigurable

Description

The MemoryDiscovery class allows you to create discovery services that keep connections in memory.

Configuration parameters

  • [connection key 1]:
  • : connection parameters for key 1
  • [connection key 2]:
  • : connection parameters for key N

Constructors

NewMemoryDiscovery

Creates a new instance of discovery service.

NewMemoryDiscovery(ctx context.Context, config *config.ConfigParam) *MemoryDiscovery

  • ctx: ctx context.Context - operation context.
  • config: *config.ConfigParam - (optional) configuration with connection parameters.

Methods

Configure

Configures component by passing configuration parameters.

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

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

ReadConnections

Reads connections from configuration parameters. Each section represents an individual Connection params.

(c *MemoryDiscovery) ReadConnections(config *config.ConfigParams)

Register

Registers connection parameters into the discovery service.

(c *MemoryDiscovery) Register(correlationId string, key string, connection *ConnectionParams) (result *ConnectionParams, err error)

  • correlationId: string - (optional) transaction id used to trace execution through the call chain.
  • key: string - key to uniquely identify the connection parameters.
  • connection: *ConnectionParams - connection to be registered.
  • returns: (result *ConnectionParams, err error) - the registered connection parameters.

ResolveAll

Resolves all connection parameters by their key.

(c *MemoryDiscovery) ResolveAll(correlationId string, key string) (result []*ConnectionParams, err error)

  • correlationId: string - (optional) transaction id to trace execution through a call chain.
  • key: string - key to uniquely identify the connections.
  • returns: (result []*ConnectionParams, err error) - list with resolved connections.

ResolveOne

Resolves a single connection parameters by its key.

(c *MemoryDiscovery) ResolveOne(correlationId string, key string) (result *ConnectionParams, err error)

  • correlationId: string - (optional) transaction id used to trace execution through a call chain.
  • key: string - key used to uniquely identify the connection.
  • returns: (result *ConnectionParams, err error) - resolved connection.

Examples

config := NewConfigParamsFromTuples(
	"key1.host", "10.1.1.100",
	"key1.port", "8080",
	"key2.host", "10.1.1.100",
	"key2.port", "8082",
)

discovery := NewMemoryDiscovery()
discovery.ReadConnections(config)
conn, err := discovery.ResolveOne("123", "key1")

// Result: host=10.1.1.100;port=8080

See also