publisher

package
v0.0.0-...-146c1f4 Latest Latest
Warning

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

Go to latest
Published: Apr 12, 2018 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	DefaultPrefix string = "being/workers"
)

Functions

This section is empty.

Types

type EtcdPublisher

type EtcdPublisher struct {
	// should be in format as being/workers/{ServiceName}
	Prefix string
	TTL    time.Duration
	Client *client.Client
	Kapi   client.KeysAPI
}

EtcdPublisher publish sevice info to etcd

func NewEtcdPublisher

func NewEtcdPublisher(hosts []string, ttl int) *EtcdPublisher

NewEtcdPublisher returns the publisher which refresh every ttl seconds

func NewEtcdPublisherWithPrefix

func NewEtcdPublisherWithPrefix(hosts []string, prefix string, ttl int) *EtcdPublisher

func (*EtcdPublisher) Heartbeat

func (ep *EtcdPublisher) Heartbeat(service *Service)

Heartbeat blocks and refresh TTL every {ttl} seconds until the service is Unregistered

func (*EtcdPublisher) Register

func (ep *EtcdPublisher) Register(service *Service) error

Register stores the info of service at registry, and keep it, refresh it

func (*EtcdPublisher) Unregister

func (ep *EtcdPublisher) Unregister(service *Service) error

Unregister removes the Publisher.FullKey at registry

type Publisher

type Publisher interface {
	Register(*Service) error
	Unregister(*Service) error
	Hearbeat(*Service)
}

type Service

type Service struct {
	ID   string `json:"id"`
	Name string `json:"name"`
	Host string `json:"host"`
	// contains filtered or unexported fields
}

Service to register

func NewService

func NewService(id, name, host string) *Service

NewService returns a new Service

func (*Service) GetIndex

func (srv *Service) GetIndex() uint64

GetIndex get lastIndex

func (*Service) SetIndex

func (srv *Service) SetIndex(index uint64)

SetIndex sets lastIndex

func (*Service) Stop

func (srv *Service) Stop()

Stop stops the heartbeat

func (*Service) String

func (srv *Service) String() string

Jump to

Keyboard shortcuts

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