discovery

package module
v0.0.0-...-20a1c6f Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 14, 2020 License: MIT Imports: 9 Imported by: 0

README

discovery

Service disovery over NATS

Documentation

Overview

Package discovery provides service disovery.

Index

Constants

View Source
const DefaultSubjectPrefix = "github.com.hatobitoio.discovery"

DefaultSubjectPrefix is the default subject prefix for messages sent by service discovery agent.

View Source
const DefaultUpdateInterval = time.Millisecond * 1000

DefaultUpdateInterval is the default update interval for agents. If an agent does not send an update within expected update interval, other agents will forget about services registered by offending agent. 10% threshold is always added.

Variables

This section is empty.

Functions

func SubjectPrefix

func SubjectPrefix(prefix string) func(*Agent) error

SubjectPrefix is an Option that sets the NATS subject prefix used by the Agent. All agents connected to the same NATS server (or servers in same NATS cluster) and using same subject prefix will share the knowledge about available services.

Types

type Agent

type Agent struct {
	// contains filtered or unexported fields
}

Agent is a service discovery agent.

func NewAgent

func NewAgent(conn *nats.Conn, opts ...Option) (*Agent, error)

NewAgent creates a new service discovery agent.

func (*Agent) ConnStateHandler

func (a *Agent) ConnStateHandler(conn *nats.Conn)

ConnStateHandler is used to monitor the state of NATS connection. This method should be called when NATS connection state changes: connect, disconnect, close. Not calling this method after connection state change will result in other agents losing the knowledge about services registered by this instance of Agent.

func (*Agent) Discover

func (a *Agent) Discover(serviceName string, includeLocal bool) []*ServiceInfo

Discover returns a list of last known addresses of a service. If includeLocal is false, the services registered by this instance of Agent using Register() will be omitted.

func (*Agent) Register

func (a *Agent) Register(info *ServiceInfo) error

Register registers a service instance making it available for discovery by other services.

func (*Agent) Start

func (a *Agent) Start() error

Start starts the discovery service

func (*Agent) Stop

func (a *Agent) Stop() error

Stop stops the discovery service. It will notify other instances that all services registered by this agent instance are no longer available. The agent will forget all known remote services immediately. Local services list is kept intact.

func (*Agent) Unregister

func (a *Agent) Unregister(info *ServiceInfo) error

Unregister removes a service instance making it unavailable for discovery by other services.

func (*Agent) Unwatch

func (a *Agent) Unwatch(serviceName string)

Unwatch stops monitoring of particular service availability.

func (*Agent) Watch

func (a *Agent) Watch(serviceName string) error

Watch expresses interest in particular service. Only watched services will be available for discovery.

type Option

type Option func(*Agent) error

Option is used to provide options to NewAgent

type ServiceInfo

type ServiceInfo struct {
	Name      string
	Address   string
	UpdatedAt time.Time
	GoodUntil time.Time
	// contains filtered or unexported fields
}

ServiceInfo provides information about single service

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL