discovery

package
v0.1.5 Latest Latest
Warning

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

Go to latest
Published: Apr 9, 2020 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// DefaultPrefix is the key prefix in etcd
	DefaultPrefix = "iget/service/grpc"
)

Functions

This section is empty.

Types

type EtcdPublisher

type EtcdPublisher struct {
	Logger util.Logger `inject:"logger.default"`
	// should be in format as iger/service/grpc/{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 and has DefaultPrefix

func NewEtcdPublisherWithPrefix

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

NewEtcdPublisherWithPrefix returns the publisher which refreshes every ttl seconds and has prefix

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 EtcdResolver

type EtcdResolver struct {
	ServiceName string // service name to resolve
	// contains filtered or unexported fields
}

EtcdResolver is the implementaion of grpc.naming.Resolver

func NewResolver

func NewResolver(serviceName, prefix string) *EtcdResolver

NewResolver return EtcdResolver with service name

func (*EtcdResolver) Resolve

func (er *EtcdResolver) Resolve(target string) (naming.Watcher, error)

Resolve to resolve the service from etcd, target is the dial address of etcd target example: "http://127.0.0.1:2379,http://127.0.0.1:12379,http://127.0.0.1:22379"

type EtcdWatcher

type EtcdWatcher struct {
	// contains filtered or unexported fields
}

EtcdWatcher is the implementaion of grpc.naming.Watcher

func (*EtcdWatcher) Close

func (ew *EtcdWatcher) Close()

Close do nothing

func (*EtcdWatcher) Next

func (ew *EtcdWatcher) Next() ([]*naming.Update, error)

Next to return the updates

type Publisher

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

Publisher is able to register and unregister service to registry

type Service

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

Service to register

func NewService

func NewService(name, host string, port int) *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