Documentation ¶
Index ¶
Constants ¶
const (
// SOH control character
SOH = "\x01"
)
Variables ¶
var ( // BaseDirectory is the Zookeeper namespace that all nodes made by this package will live. // This path must begin with '/' BaseDirectory = "/discovery" // MemberPrefix is prefix for the Zookeeper sequential ephemeral nodes. // member_ is used by Finagle server sets. MemberPrefix = "member_" )
var BaseZnodePath = func(environment Environment, service string) string { return BaseDirectory + "/" + string(environment) + "/" + 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`
var DefaultZKTimeout = 5 * time.Second
DefaultZKTimeout is the zookeeper timeout used if it is not overwritten.
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.
type Environment ¶
type Environment string
An Environment is the test/staging/production state of the service.
const ( Local Environment = "local" Production Environment = "prod" Test Environment = "test" Staging Environment = "staging" )
Typically used environments
type ServerSet ¶
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 ¶
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) Watch ¶
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 ¶
ZookeeperServers returns the Zookeeper servers this set is using. Useful to check if everything is configured correctly.
type Watch ¶
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 ¶
Endpoints returns a slice of the current list of servers/endpoints associated with this watch.