kit: Index | Files

package zk

import ""

Package zk provides Instancer and Registrar implementations for ZooKeeper.


Package Files

client.go doc.go instancer.go logwrapper.go registrar.go


const (
    // DefaultConnectTimeout is the default timeout to establish a connection to
    // a ZooKeeper node.
    DefaultConnectTimeout = 2 * time.Second
    // DefaultSessionTimeout is the default timeout to keep the current
    // ZooKeeper session alive during a temporary disconnect.
    DefaultSessionTimeout = 5 * time.Second


var (
    DefaultACL            = zk.WorldACL(zk.PermAll)
    ErrInvalidCredentials = errors.New("invalid credentials provided")
    ErrClientClosed       = errors.New("client service closed")
    ErrNotRegistered      = errors.New("not registered")
    ErrNodeNotFound       = errors.New("node not found")

DefaultACL is the default ACL to use for creating znodes.

type Client Uses

type Client interface {
    // GetEntries should query the provided path in ZooKeeper, place a watch on
    // it and retrieve data from its current child nodes.
    GetEntries(path string) ([]string, <-chan zk.Event, error)
    // CreateParentNodes should try to create the path in case it does not exist
    // yet on ZooKeeper.
    CreateParentNodes(path string) error
    // Register a service with ZooKeeper.
    Register(s *Service) error
    // Deregister a service with ZooKeeper.
    Deregister(s *Service) error
    // Stop should properly shutdown the client implementation

Client is a wrapper around a lower level ZooKeeper client implementation.

func NewClient Uses

func NewClient(servers []string, logger log.Logger, options ...Option) (Client, error)

NewClient returns a ZooKeeper client with a connection to the server cluster. It will return an error if the server cluster cannot be resolved.

type Instancer Uses

type Instancer struct {
    // contains filtered or unexported fields

Instancer yield instances stored in a certain ZooKeeper path. Any kind of change in that path is watched and will update the subscribers.

func NewInstancer Uses

func NewInstancer(c Client, path string, logger log.Logger) (*Instancer, error)

NewInstancer returns a ZooKeeper Instancer. ZooKeeper will start watching the given path for changes and update the Instancer endpoints.

func (*Instancer) Deregister Uses

func (s *Instancer) Deregister(ch chan<- sd.Event)

Deregister implements Instancer.

func (*Instancer) Register Uses

func (s *Instancer) Register(ch chan<- sd.Event)

Register implements Instancer.

func (*Instancer) Stop Uses

func (s *Instancer) Stop()

Stop terminates the Instancer.

type Option Uses

type Option func(*clientConfig) error

Option functions enable friendly APIs.

func ACL Uses

func ACL(acl []zk.ACL) Option

ACL returns an Option specifying a non-default ACL for creating parent nodes.

func ConnectTimeout Uses

func ConnectTimeout(t time.Duration) Option

ConnectTimeout returns an Option specifying a non-default connection timeout when we try to establish a connection to a ZooKeeper server.

func Credentials Uses

func Credentials(user, pass string) Option

Credentials returns an Option specifying a user/password combination which the client will use to authenticate itself with.

func EventHandler Uses

func EventHandler(handler func(zk.Event)) Option

EventHandler returns an Option specifying a callback function to handle incoming zk.Event payloads (ZooKeeper connection events).

func Payload Uses

func Payload(payload [][]byte) Option

Payload returns an Option specifying non-default data values for each znode created by CreateParentNodes.

func SessionTimeout Uses

func SessionTimeout(t time.Duration) Option

SessionTimeout returns an Option specifying a non-default session timeout.

type Registrar Uses

type Registrar struct {
    // contains filtered or unexported fields

Registrar registers service instance liveness information to ZooKeeper.

func NewRegistrar Uses

func NewRegistrar(client Client, service Service, logger log.Logger) *Registrar

NewRegistrar returns a ZooKeeper Registrar acting on the provided catalog registration.

func (*Registrar) Deregister Uses

func (r *Registrar) Deregister()

Deregister implements sd.Registrar interface.

func (*Registrar) Register Uses

func (r *Registrar) Register()

Register implements sd.Registrar interface.

type Service Uses

type Service struct {
    Path string // discovery namespace, example: /myorganization/myplatform/
    Name string // service name, example: addscv
    Data []byte // instance data to store for discovery, example:
    // contains filtered or unexported fields

Service holds the root path, service name and instance identifying data you want to publish to ZooKeeper.

Package zk imports 9 packages (graph) and is imported by 3 packages. Updated 2019-04-07. Refresh now. Tools for package owners.