serversets

package
v2.0.6 Latest Latest
Warning

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

Go to latest
Published: Apr 28, 2023 License: MIT, MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// SOH control character
	SOH = "\x01"
)

Variables

View Source
var BaseZnodePath = func(_ Environment, service string) string {
	return fmt.Sprintf(config.GddZkDirectoryPattern.LoadOrDefault(config.DefaultGddZkDirectoryPattern), service)
}

BaseZnodePath allows for a custom Zookeeper directory structure. This function should return the path where you want the service's members to live. Default is `BaseDirectory + "/" + environment + "/" + service` where the default base directory is `/discovery` TODO decide how to make use of Environment

View Source
var DefaultZKTimeout = 5 * time.Second

DefaultZKTimeout is the zookeeper timeout used if it is not overwritten.

View Source
var (

	// MemberPrefix is prefix for the Zookeeper sequential ephemeral nodes.
	// member_ is used by Finagle server sets.
	MemberPrefix = "member_"
)

Functions

This section is empty.

Types

type Endpoint

type Endpoint struct {
	*ServerSet
	PingRate   time.Duration // default/initial is 1 second
	CloseEvent chan struct{}
	// contains filtered or unexported fields
}

An Endpoint is a service (host and port) registered on Zookeeper to be discovered by clients/watchers.

func (*Endpoint) Close

func (ep *Endpoint) Close()

Close blocks until the client connection to Zookeeper is closed. If already called, will simply return, even if in the process of closing.

type Environment

type Environment string

An Environment is the test/staging/production state of the service.

const (
	Local      Environment = "local"
	Dev        Environment = "dev"
	Production Environment = "prod"
	Test       Environment = "test"
	Uat        Environment = "uat"
	Staging    Environment = "staging"
)

Typically used environments

type ServerSet

type ServerSet struct {
	ZKTimeout time.Duration
	// contains filtered or unexported fields
}

A ServerSet represents a service with a set of servers that may change over time. The master lists of servers is kept as ephemeral nodes in Zookeeper.

func New

func New(environment Environment, service string, zookeepers []string) *ServerSet

New creates a new ServerSet object that can then be watched or have an endpoint added to. The service name must not contain any slashes. Will panic if it does.

func (*ServerSet) RegisterEndpoint

func (ss *ServerSet) RegisterEndpoint(host string, port int, ping func() error) (*Endpoint, error)

RegisterEndpoint registers a host and port as alive. It creates the appropriate Zookeeper nodes and watchers will be notified this server/endpoint is available.

func (*ServerSet) RegisterEndpointWithMeta

func (ss *ServerSet) RegisterEndpointWithMeta(host string, port int, ping func() error, meta map[string]interface{}) (*Endpoint, error)

func (*ServerSet) Watch

func (ss *ServerSet) Watch() (*Watch, error)

Watch creates a new watch on this server set. Changes to the set will update watch.Endpoints() and an event will be sent to watch.Event right after that happens.

func (*ServerSet) ZookeeperServers

func (ss *ServerSet) ZookeeperServers() []string

ZookeeperServers returns the Zookeeper servers this set is using. Useful to check if everything is configured correctly.

type Watch

type Watch struct {
	LastEvent  time.Time
	EventCount int
	// contains filtered or unexported fields
}

A Watch keeps tabs on a server set in Zookeeper and notifies via the Event() channel when the list of servers changes. The list of servers is updated automatically and will be up to date when the Event is sent.

func (*Watch) Close

func (w *Watch) Close()

Close blocks until the underlying Zookeeper connection is closed.

func (*Watch) Endpoints

func (w *Watch) Endpoints() []string

Endpoints returns a slice of the current list of servers/endpoints associated with this watch.

func (*Watch) Event

func (w *Watch) Event() <-chan struct{}

Event returns the event channel. This channel will get an object whenever something changes with the list of endpoints.

func (*Watch) IsClosed

func (w *Watch) IsClosed() bool

IsClosed returns if this watch has been closed. This is a way for libraries wrapping this package to know if their underlying watch is closed and should stop looking for events.

Jump to

Keyboard shortcuts

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