Documentation ¶
Index ¶
Constants ¶
const ( // HeartbeatIntervalSecs is the expected interval at which services register themselves. HeartbeatIntervalSecs = 5 // MissedHearbeatTTL allows for services to miss a heartbeat before being set to offline. MissedHearbeatTTL = 5 )
const KeyPrefix = "/discover"
KeyPrefix is used to create the full service path.
Variables ¶
var Attempts = attempt.Strategy{ Min: 5, Total: 5 * time.Second, Delay: 200 * time.Millisecond, }
Attempts is the attempt strategy that is used to connect to etcd.
Functions ¶
func ListenAndServe ¶
ListenAndServe starts the the discoverd agent.
Types ¶
type Agent ¶
type Agent struct { Backend DiscoveryBackend Address string }
Agent represents the discoverd server--the backend its using, where it's listening, etc.
func (*Agent) Subscribe ¶
Subscribe returns a stream of ServiceUpdate objects for the given service name.
func (*Agent) Unregister ¶
Unregister announces a service has gone offline.
type DiscoveryBackend ¶
type DiscoveryBackend interface { Subscribe(name string) (UpdateStream, error) Register(name string, addr string, attrs map[string]string) error Unregister(name string, addr string) error }
DiscoveryBackend represents a system that registers/unregisters services and notifies on updates.
type EtcdBackend ¶
EtcdBackend for service discovery.
func (*EtcdBackend) Register ¶
func (b *EtcdBackend) Register(name, addr string, attrs map[string]string) error
Register a service with etcd.
func (*EtcdBackend) Subscribe ¶
func (b *EtcdBackend) Subscribe(name string) (UpdateStream, error)
Subscribe to changes in services of a given name.
func (*EtcdBackend) Unregister ¶
func (b *EtcdBackend) Unregister(name, addr string) error
Unregister a service with etcd.
type ServiceUpdate ¶
type ServiceUpdate struct { Name string Addr string Online bool Attrs map[string]string Created uint }
ServiceUpdate is sent when a service comes online or goes offline.
type UpdateStream ¶
type UpdateStream interface { Chan() chan *ServiceUpdate Close() }
UpdateStream represents a subscription to changes in service registration.