Documentation ¶
Index ¶
- Constants
- Variables
- type Endpoint
- type Environment
- type ServerSet
- func (ss *ServerSet) RegisterEndpoint(host string, port int, ping func() error) (*Endpoint, error)
- func (ss *ServerSet) RegisterEndpointWithMeta(host string, port int, ping func() error, meta map[string]interface{}) (*Endpoint, error)
- func (ss *ServerSet) Watch() (*Watch, error)
- func (ss *ServerSet) ZookeeperServers() []string
- type Watch
Constants ¶
const (
// SOH control character
SOH = "\x01"
)
Variables ¶
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
var DefaultZKTimeout = 5 * time.Second
DefaultZKTimeout is the zookeeper timeout used if it is not overwritten.
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.
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 ¶
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) RegisterEndpointWithMeta ¶
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.