sd

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Oct 3, 2017 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package sd provides utilities related to service discovery. That includes the client-side loadbalancer pattern, where a microservice subscribes to a service discovery system in order to reach remote instances; as well as the registrator pattern, where a microservice registers itself in a service discovery system. Implementations are provided for most common systems.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DefaultEndpointer added in v0.5.0

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

DefaultEndpointer implements an Endpointer interface. When created with NewEndpointer function, it automatically registers as a subscriber to events from the Instances and maintains a list of active Endpoints.

func NewEndpointer added in v0.5.0

func NewEndpointer(src Instancer, f Factory, logger log.Logger, options ...EndpointerOption) *DefaultEndpointer

NewEndpointer creates an Endpointer that subscribes to updates from Instancer src and uses factory f to create Endpoints. If src notifies of an error, the Endpointer keeps returning previously created Endpoints assuming they are still good, unless this behavior is disabled via InvalidateOnError option.

func (*DefaultEndpointer) Close added in v0.5.0

func (de *DefaultEndpointer) Close()

Close deregisters DefaultEndpointer from the Instancer and stops the internal go-routine.

func (*DefaultEndpointer) Endpoints added in v0.5.0

func (de *DefaultEndpointer) Endpoints() ([]endpoint.Endpoint, error)

Endpoints implements Endpointer.

type Endpointer added in v0.5.0

type Endpointer interface {
	Endpoints() ([]endpoint.Endpoint, error)
}

Endpointer listens to a service discovery system and yields a set of identical endpoints on demand. An error indicates a problem with connectivity to the service discovery system, or within the system itself; an Endpointer may yield no endpoints without error.

type EndpointerOption added in v0.5.0

type EndpointerOption func(*endpointerOptions)

EndpointerOption allows control of endpointCache behavior.

func InvalidateOnError added in v0.5.0

func InvalidateOnError(timeout time.Duration) EndpointerOption

InvalidateOnError returns EndpointerOption that controls how the Endpointer behaves when then Instancer publishes an Event containing an error. Without this option the Endpointer continues returning the last known endpoints. With this option, the Endpointer continues returning the last known endpoints until the timeout elapses, then closes all active endpoints and starts returning an error. Once the Instancer sends a new update with valid resource instances, the normal operation is resumed.

type Event added in v0.5.0

type Event struct {
	Instances []string
	Err       error
}

Event represents a push notification generated from the underlying service discovery implementation. It contains either a full set of available resource instances, or an error indicating some issue with obtaining information from discovery backend. Examples of errors may include loosing connection to the discovery backend, or trying to look up resource instances using an incorrectly formatted key. After receiving an Event with an error the listenter should treat previously discovered resource instances as stale (although it may choose to continue using them). If the Instancer is able to restore connection to the discovery backend it must push another Event with the current set of resource instances.

type Factory

type Factory func(instance string) (endpoint.Endpoint, io.Closer, error)

Factory is a function that converts an instance string (e.g. host:port) to a specific endpoint. Instances that provide multiple endpoints require multiple factories. A factory also returns an io.Closer that's invoked when the instance goes away and needs to be cleaned up. Factories may return nil closers.

Users are expected to provide their own factory functions that assume specific transports, or can deduce transports by parsing the instance string.

type FixedEndpointer added in v0.5.0

type FixedEndpointer []endpoint.Endpoint

FixedEndpointer yields a fixed set of endpoints.

func (FixedEndpointer) Endpoints added in v0.5.0

func (s FixedEndpointer) Endpoints() ([]endpoint.Endpoint, error)

Endpoints implements Endpointer.

type FixedInstancer added in v0.5.0

type FixedInstancer []string

FixedInstancer yields a fixed set of instances.

func (FixedInstancer) Deregister added in v0.5.0

func (d FixedInstancer) Deregister(ch chan<- Event)

Deregister implements Instancer.

func (FixedInstancer) Register added in v0.5.0

func (d FixedInstancer) Register(ch chan<- Event)

Register implements Instancer.

func (FixedInstancer) Stop added in v0.6.0

func (d FixedInstancer) Stop()

Stop implements Instancer.

type Instancer added in v0.5.0

type Instancer interface {
	Register(chan<- Event)
	Deregister(chan<- Event)
	Stop()
}

Instancer listens to a service discovery system and notifies registered observers of changes in the resource instances. Every event sent to the channels contains a complete set of instances known to the Instancer. That complete set is sent immediately upon registering the channel, and on any future updates from discovery system.

type Registrar

type Registrar interface {
	Register()
	Deregister()
}

Registrar registers instance information to a service discovery system when an instance becomes alive and healthy, and deregisters that information when the service becomes unhealthy or goes away.

Registrar implementations exist for various service discovery systems. Note that identifying instance information (e.g. host:port) must be given via the concrete constructor; this interface merely signals lifecycle changes.

Directories

Path Synopsis
Package consul provides Instancer and Registrar implementations for Consul.
Package consul provides Instancer and Registrar implementations for Consul.
Package dnssrv provides an Instancer implementation for DNS SRV records.
Package dnssrv provides an Instancer implementation for DNS SRV records.
Package etcd provides an Instancer and Registrar implementation for etcd.
Package etcd provides an Instancer and Registrar implementation for etcd.
Package eureka provides Instancer and Registrar implementations for Netflix OSS's Eureka
Package eureka provides Instancer and Registrar implementations for Netflix OSS's Eureka
internal
Package lb implements the client-side load balancer pattern.
Package lb implements the client-side load balancer pattern.
Package zk provides Instancer and Registrar implementations for ZooKeeper.
Package zk provides Instancer and Registrar implementations for ZooKeeper.

Jump to

Keyboard shortcuts

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