service

package
v0.0.0-...-c5065e6 Latest Latest
Warning

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

Go to latest
Published: Mar 31, 2020 License: Apache-2.0 Imports: 10 Imported by: 1

Documentation

Index

Constants

View Source
const (
	DefaultWatchPollInterval = time.Duration(5 * time.Minute)
)

Variables

View Source
var (
	ErrorNotRunning               = errors.New("Discovery client not running")
	ErrorInvalidWatchPollInterval = errors.New("The WatchPollInterval must be a valid time.Duration or an integral seconds value")
)

Functions

func HttpAddress

func HttpAddress(serviceInstance *discovery.ServiceInstance) string

HttpAddress is a KeyFunc which maps a ServiceInstance onto a well-formed http or https URL

func InstanceId

func InstanceId(serviceInstance *discovery.ServiceInstance) string

InstanceId is a KeyFunc which maps a service instance to its unique identifier

func Spec

func Spec(serviceInstance *discovery.ServiceInstance) string

Spec is a KeyFunc which maps a ServiceInstance onto ServiceInstance.Spec()

Types

type Discovery

type Discovery interface {
	// Connected indicates whether this discovery is actually connected to a zookeeper ensemble
	Connected() bool

	// ServiceCount returns the number of watched services in associated with this Discovery
	ServiceCount() int

	// ServiceNames returns an independent slice containing the names of the watched services
	// available in this Discovery
	ServiceNames() []string

	// FetchServices returns an Instances containing the set of services with the given name.
	// If no services by that name are watched, this method returns an error.
	FetchServices(serviceName string) (Instances, error)

	// AddListener registers a listener for the given service name.
	AddListener(serviceName string, listener Listener)

	// RemoveListener deregisters a listener for the given service name
	RemoveListener(serviceName string, listener Listener)

	// BlockUntilConnected blocks until the underlying Curator implementation
	// is in a connected state with Zookeeper
	BlockUntilConnected() error

	// BlockUntilConnectedTimeout is like BlockUntilConnected, except that it will
	// abort with an error if the specified time elapses without the underlying
	// Curator implementation transitioning into a connected state.
	BlockUntilConnectedTimeout(maxWaitTime time.Duration) error

	// Run starts this Discovery instance.  It is idempotent.
	Run(waitGroup *sync.WaitGroup, shutdown <-chan struct{}) error
}

Discovery represents a service discovery endpoint. Instances are created using a DiscoveryBuilder.

type DiscoveryBuilder

type DiscoveryBuilder struct {
	// Connection is the Curator connection string.  It's a comma-delimited
	// list of zookeeper server nodes
	Connection string `json:"connection"`

	// BasePath is the parent znode path for all registrations and watches
	// for Discovery instances produced by this builder
	BasePath string `json:"basePath"`

	// Registrations holds any service instances that are maintained in zookeeper
	// under the BasePath.
	Registrations Instances `json:"registrations"`

	// Watches contains the names of services, registered under the BasePath,
	// to listen for changes
	Watches []string `json:"watches"`

	// WatchPollInterval is the polling interval for any watched services.
	// Polling is used in addition to setting watches if this value is set.
	// If this value is not supplied, DefaultWatchPollInterval is used instead.
	//
	// This value is ignored if there are no Watches set.
	WatchPollInterval string `json:"watchPollInterval"`
}

DiscoveryBuilder provides a configurable DiscoveryFactory implementation. This type also implements a standard JSON configuration.

func (*DiscoveryBuilder) New

func (this *DiscoveryBuilder) New(logger zk.Logger) (discovery Discovery, err error)

New creates a distinct Discovery instance from this DiscoveryBuilder. Changes to this builder will not affect the newly created Discovery instance, and vice versa.

type Instances

type Instances []*discovery.ServiceInstance

Instances is a custom slice type that stores ServiceInstances. It also provides a simple API that clients can use when building other data structures.

func (Instances) Len

func (this Instances) Len() int

Len() is a shortcut for len(this)

func (Instances) RegisterWith

func (this Instances) RegisterWith(serviceDiscovery *discovery.ServiceDiscovery) error

RegisterWith registers each instance in this slice with the supplied service discovery. This method normalizes each ServiceInstance, using the discovery API to create a new instance with internal data members set (e.g. timestamps).

func (Instances) String

func (this Instances) String() string

String outputs a string representation of this Instances, useful for debugging. This method follows pointers to make the debug output more useful.

func (Instances) ToKeyMap

func (this Instances) ToKeyMap(keyFunc KeyFunc, output KeyMap)

ToKeyMap maps each ServiceInstance onto a string key as in ToKeys, but both the key and the ServiceInstance value are stored in the output.

func (Instances) ToKeys

func (this Instances) ToKeys(keyFunc KeyFunc, output Keys)

ToKeys maps each ServiceInstance onto a string key via keyFunc, then invokes Keys.Add() for each key.

type KeyFunc

type KeyFunc func(*discovery.ServiceInstance) string

KeyFunc defines the function signature for functions which can map ServiceInstances onto string keys

type KeyMap

type KeyMap map[string]*discovery.ServiceInstance

KeyMap is a convenient map type which can store both the result of a KeyFunc and the associated ServiceInstance

type Keys

type Keys interface {
	Add(string)
}

Keys defines the method set for types which can receive the output of a KeyFunc

type Listener

type Listener interface {
	// ServicesChanged is invoked anytime a Watcher notices that the set of services
	// with a given name has changed.
	ServicesChanged(serviceName string, instances Instances)
}

Listener receives notifications when the set of watched services has changed.

type ListenerFunc

type ListenerFunc func(string, Instances)

ListenerFunc is the function type that corresponds to Listener

func (ListenerFunc) ServicesChanged

func (f ListenerFunc) ServicesChanged(serviceName string, instances Instances)

Jump to

Keyboard shortcuts

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