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 = "/aurora" // MemberPrefix is prefix for the Zookeeper sequential ephemeral nodes. // member_ is used by Finagle server sets. MemberPrefix = "member_" )
var BaseZnodePath = func(role, environment, service string) string { return BaseDirectory + "/" + role + "/" + 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 `/aurora`
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 FinagleFmt ¶
type FinagleFmt struct {
// contains filtered or unexported fields
}
FinagleFmt provides Finagle style path/data formats.
func NewFinagleFmt ¶
func NewFinagleFmt(role, environment, service string) FinagleFmt
NewFinagleFmt creates a new FinagleFmt.
func (FinagleFmt) Create ¶
func (FinagleFmt) Create(host string, port int) ZKRecord
Create creates an alive endpoint record from host and port.
func (FinagleFmt) Path ¶
func (f FinagleFmt) Path() string
Path returns the znode path where all service members reside.
func (FinagleFmt) Prefix ¶
func (f FinagleFmt) Prefix() string
Prefix returns the service member name prefix.
type FinagleRecord ¶
type FinagleRecord struct { ServiceEndpoint endpoint `json:"serviceEndpoint"` AdditionalEndpoints map[string]endpoint `json:"additionalEndpoints"` Shard int64 `json:"shard"` Status string `json:"status"` }
FinagleRecord is structure of the data in each member znode. It mimics finagle serverset structure.
func (*FinagleRecord) Endpoint ¶
func (f *FinagleRecord) Endpoint() string
Endpoint returns host:port.
func (*FinagleRecord) IsAlive ¶
func (f *FinagleRecord) IsAlive() bool
IsAlive returns true if this endpoint is to be discovered by user.
func (*FinagleRecord) Marshal ¶
func (f *FinagleRecord) Marshal() ([]byte, error)
Marshal encodes zk record in JSON format.
type ServerSet ¶
type ServerSet struct { ZKTimeout time.Duration ZKFmt ZKFmt // 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 ¶
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 starts a zookeeper connection and starts watching changes in the service members znode.
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.
type ZKFmt ¶
type ZKFmt interface { // Path returns the zokeeper full path to service members. Path() string // Prefix returns the znode name prefix for service members. Prefix() string // CreateRecord creates a new endpoint record from host and port. Create(host string, port int) ZKRecord // Unmarshal decodes encoded endpoint data a ZKrecord. Unmarshal([]byte) (ZKRecord, error) }
ZKFmt defines the APIs for endpoint's zookeeper path and data formats.
type ZKRecord ¶
type ZKRecord interface { // Marshal encodes data to be stored in zookeeper. Marshal() ([]byte, error) // Endpoint returns the endpoint as host:port string Endpoint() string // IsAlive returns true if znode has liveness information stored. IsAlive() bool }
ZKRecord defines the APIs an endpoint record in zookeeper should provide.