disco

package
v3.3.14 Latest Latest
Warning

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

Go to latest
Published: Sep 17, 2020 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultConfig = &Config{
	RandomSource: rand.Reader,
	Logger:       log.DefaultLogger.CreateChild(),
}

DefaultConfig is used if any config values are nil

View Source
var ErrDuplicateAdvertise = errors.New("service name already advertised")

ErrDuplicateAdvertise is returned by Advertise if users try to Advertise the same service name twice

Functions

This section is empty.

Types

type ChangeWatch

type ChangeWatch func()

ChangeWatch is a callback you can register on a service that is executed whenever the service's instances change

type Config

type Config struct {
	RandomSource io.Reader
	Logger       log.Logger
}

Config controls optional parameters for disco

type Disco

type Disco struct {
	GUIDbytes [16]byte
	// contains filtered or unexported fields
}

Disco is a service discovery framework orchestrated via zookeeper

func New

func New(zkConnCreator ZkConnCreator, publishAddress string, config *Config) (*Disco, error)

New creates a disco discovery/publishing service

func (*Disco) Advertise

func (d *Disco) Advertise(serviceName string, payload interface{}, port uint16) (err error)

Advertise yourself as hosting a service

func (*Disco) Close

func (d *Disco) Close()

Close any open disco connections making this disco unreliable for future updates

func (*Disco) CreatePersistentEphemeralNode

func (d *Disco) CreatePersistentEphemeralNode(path string, payload []byte) (err error)

CreatePersistentEphemeralNode creates a persistent ephemeral node

func (*Disco) DeleteAdvertisedService

func (d *Disco) DeleteAdvertisedService(serviceName string)

DeleteAdvertisedService deletes a specific advertised service name

func (*Disco) DeleteAdvertisedServices

func (d *Disco) DeleteAdvertisedServices()

DeleteAdvertisedServices deletes all advertised services

func (*Disco) GUID

func (d *Disco) GUID() string

GUID that this disco advertises itself as

func (*Disco) NinjaMode

func (d *Disco) NinjaMode(ninjaMode bool)

NinjaMode will have future Advertise() calls no-op. This is useful when connecting an application to a production or testing tier and not wanting to advertise yourself for incomming connections,

func (*Disco) Services

func (d *Disco) Services(serviceName string) (*Service, error)

Services advertising for serviceName

func (*Disco) Var

func (d *Disco) Var() expvar.Var

Var returns an expvar variable that shows all the current disco services and the current list of endpoints seen for each service

type Service

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

Service is a set of ServiceInstance that describe a discovered service

func (*Service) ForceInstances

func (s *Service) ForceInstances(instances []ServiceInstance)

ForceInstances overrides a disco service to have exactly the passed instances forever. Useful for debugging.

func (*Service) ServiceInstances

func (s *Service) ServiceInstances() []ServiceInstance

ServiceInstances that represent instances of this service in your system

func (*Service) StateLog added in v3.3.0

func (s *Service) StateLog() log.Logger

StateLog is returned for nesting in wrapping clients.

func (*Service) String

func (s *Service) String() string

func (*Service) Watch

func (s *Service) Watch(watch ChangeWatch)

Watch for changes to the members of this service

type ServiceInstance

type ServiceInstance struct {
	ID                  string      `json:"id"`
	Name                string      `json:"name"`
	Payload             interface{} `json:"payload,omitempty"`
	Address             string      `json:"address"`
	Port                uint16      `json:"port"`
	RegistrationTimeUTC int64       `json:"registrationTimeUTC"`
	SslPort             *uint16     `json:"sslPort"`
	ServiceType         string      `json:"serviceType"`
	URISpec             *string     `json:"uriSpec"`
}

ServiceInstance defines a remote service and is similar to https://curator.apache.org/apidocs/org/apache/curator/x/discovery/ServiceInstanceBuilder.html

func (*ServiceInstance) DialString

func (s *ServiceInstance) DialString() string

DialString is a string that net.Dial() can accept that will connect to this service's Port

type ZkConn

type ZkConn interface {
	GetW(path string) ([]byte, *zk.Stat, <-chan zk.Event, error)
	Create(path string, data []byte, flags int32, acl []zk.ACL) (string, error)
	ChildrenW(path string) ([]string, *zk.Stat, <-chan zk.Event, error)
	ExistsW(path string) (bool, *zk.Stat, <-chan zk.Event, error)
	Delete(path string, version int32) error
	Close()
}

ZkConn does zookeeper connections

type ZkConnCreator

type ZkConnCreator interface {
	Connect() (ZkConn, <-chan zk.Event, error)
}

ZkConnCreator creates Zk connections for disco to use.

func BuilderConnector

func BuilderConnector(b *zkplus.Builder) ZkConnCreator

BuilderConnector satisfies the disco zk connect interface for a zkplus.Builder

type ZkConnCreatorFunc

type ZkConnCreatorFunc func() (ZkConn, <-chan zk.Event, error)

ZkConnCreatorFunc gives you a ZkConnCreator out of a function

func (ZkConnCreatorFunc) Connect

func (z ZkConnCreatorFunc) Connect() (ZkConn, <-chan zk.Event, error)

Connect to a zookeeper endpoint

Jump to

Keyboard shortcuts

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