disco

package
Version: v2.5.1+incompatible Latest Latest
Warning

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

Go to latest
Published: Oct 4, 2019 License: Apache-2.0 Imports: 21 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

View Source
var ErrNoInstance = errors.New("no thrift instances in disco")

ErrNoInstance is returned by NextConnection if the service has no instances

View Source
var ErrNoInstanceOpen = errors.New("no thrift instances is open")

ErrNoInstanceOpen is returned by NextConnection if it cannot connect to any service ports

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 added in v1.1.6

func (d *Disco) DeleteAdvertisedService(serviceName string)

DeleteAdvertisedService deletes a specific advertised service name

func (*Disco) DeleteAdvertisedServices added in v1.1.6

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) 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 ThriftTransport

type ThriftTransport struct {
	WrappedFactory thrift.TTransportFactory

	Dialer net.Dialer
	// contains filtered or unexported fields
}

ThriftTransport can be used as the transport layer for thrift, connecting to services discovered by disco

func NewThriftTransport

func NewThriftTransport(service *Service, timeout time.Duration) *ThriftTransport

NewThriftTransport creates a new ThriftTransport. The default transport factory is TFramed

func NewThriftTransportWithMaxBufferSize

func NewThriftTransportWithMaxBufferSize(service *Service, timeout time.Duration, maxLength uint32) *ThriftTransport

NewThriftTransportWithMaxBufferSize creates a new ThriftTransport for TFramedTransport but sets the maximum size for request frames.

func (*ThriftTransport) Close

func (d *ThriftTransport) Close() error

Close and nil the underline transport

func (*ThriftTransport) Flush

func (d *ThriftTransport) Flush() (err error)

Flush the underline transport

func (*ThriftTransport) IsOpen

func (d *ThriftTransport) IsOpen() bool

IsOpen will return true if there is a connected underline transport and it is open

func (*ThriftTransport) NextConnection

func (d *ThriftTransport) NextConnection() error

NextConnection will connect this transport to another random disco service, or return an error if no disco service can be dialed

func (*ThriftTransport) NextConnectionN added in v1.1.6

func (d *ThriftTransport) NextConnectionN(startIndex int) error

NextConnectionN will connect this transport disco service, or return an error if no disco service can be dialed

func (*ThriftTransport) Open

func (d *ThriftTransport) Open() error

Open a connection if one does not exist, otherwise do nothing.

func (*ThriftTransport) Read

func (d *ThriftTransport) Read(b []byte) (n int, err error)

Read bytes from underline transport if it is not nil. Exact definition defined in TTransport

func (*ThriftTransport) RemainingBytes

func (d *ThriftTransport) RemainingBytes() uint64

RemainingBytes of underline transport, or maxSize if not set

func (*ThriftTransport) Write

func (d *ThriftTransport) Write(b []byte) (n int, err error)

Write bytes to underline transport if it is not nil. Exact definition defined in TTransport

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

Source Files

Jump to

Keyboard shortcuts

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