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.
Most of the code in this package is taken from the awesome Go kit library and adjusted so generic clients can be created and no dependency on the Go kit Endpoint concept is needed. Where possible it uses the Go kit sd package.
See https:/gokit.io for more.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrNoClients = errors.New("no client instance available")
ErrNoClients is returned when no qualifying client instances are available.
Functions ¶
This section is empty.
Types ¶
type Balancer ¶
type Balancer interface {
Client() (interface{}, error)
}
Balancer yields client instances according to some heuristic.
func NewRoundRobin ¶
func NewRoundRobin(s ClientInstancer) Balancer
NewRoundRobin returns a load balancer that returns services in sequence.
type ClientInstancer ¶
type ClientInstancer interface {
Clients() ([]interface{}, error)
}
ClientInstancer listens to a service discovery system and yields a set of identical client instances on demand. An error indicates a problem with connectivity to the service discovery system, or within the system itself; an ClientInstancer may yield no client instances without error.
type DefaultClientInstancer ¶
type DefaultClientInstancer struct {
// contains filtered or unexported fields
}
DefaultClientInstancer implements an ClientInstancer interface. When created with NewClientInstancer function, it automatically registers as a subscriber to events from the Instances and maintains a list of active client instances.
func NewClientInstancer ¶
func NewClientInstancer( src sd.Instancer, f Factory, logger log.Logger, options ...Option, ) *DefaultClientInstancer
NewClientInstancer creates a ClientInstancer that subscribes to updates from Instancer src and uses factory f to create Client instances. If src notifies of an error, the ClientInstancer keeps returning previously created Client instances assuming they are still good, unless this behavior is disabled via InvalidateOnError option.
func (*DefaultClientInstancer) Clients ¶
func (dc *DefaultClientInstancer) Clients() ([]interface{}, error)
Clients implements ClientInstancer.
func (*DefaultClientInstancer) Close ¶
func (dc *DefaultClientInstancer) Close()
Close deregisters DefaultClientInstancer from the Instancer and stops the internal go-routine.
type Factory ¶
Factory is a function that converts an instance string (e.g. host:port) to a specific client implementation. 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 FixedClientInstancer ¶
type FixedClientInstancer []interface{}
FixedClientInstancer yields a fixed set of client instances.
func (FixedClientInstancer) Clients ¶
func (s FixedClientInstancer) Clients() ([]interface{}, error)
Clients implements ClientInstancer.
type Option ¶
type Option func(*clientInstancerOptions)
Option allows control of clientCache behavior.
func InvalidateOnError ¶
InvalidateOnError returns Option that controls how the ClientInstancer behaves when then Instancer publishes an Event containing an error. Without this option the ClientInstancer continues returning the last known client instances. With this option, the ClientInstancer continues returning the last known client instances until the timeout elapses, then closes all active client instances and starts returning an error. Once the Instancer sends a new update with valid resource instances, the normal operation is resumed.