agent

package
v0.0.0-...-dd9b67b Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 2, 2014 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
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
)
View Source
const KeyPrefix = "/discover"

KeyPrefix is used to create the full service path.

Variables

View Source
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

func ListenAndServe(server *Agent) error

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 NewServer

func NewServer(addr string, etcdAddrs []string) *Agent

NewServer creates a new discoverd server listening at addr and backed by etcd.

func (*Agent) Register

func (s *Agent) Register(args *Args, ret *string) error

Register announces a service is online at an address.

func (*Agent) Subscribe

func (s *Agent) Subscribe(args *Args, stream rpcplus.Stream) error

Subscribe returns a stream of ServiceUpdate objects for the given service name.

func (*Agent) Unregister

func (s *Agent) Unregister(args *Args, ret *struct{}) error

Unregister announces a service has gone offline.

type Args

type Args struct {
	Name  string
	Addr  string
	Attrs map[string]string
}

Args represents the data sent to discoverd's register and unregister API methods.

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

type EtcdBackend struct {
	Client *etcd.Client
}

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL