Documentation ¶
Index ¶
- Variables
- type ChangeWatch
- type Config
- type Disco
- func (d *Disco) Advertise(serviceName string, payload interface{}, port uint16) (err error)
- func (d *Disco) Close()
- func (d *Disco) CreatePersistentEphemeralNode(path string, payload []byte) (err error)
- func (d *Disco) DeleteAdvertisedService(serviceName string)
- func (d *Disco) DeleteAdvertisedServices()
- func (d *Disco) GUID() string
- func (d *Disco) NinjaMode(ninjaMode bool)
- func (d *Disco) Services(serviceName string) (*Service, error)
- func (d *Disco) Var() expvar.Var
- type Service
- type ServiceInstance
- type ThriftTransport
- func (d *ThriftTransport) Close() error
- func (d *ThriftTransport) Flush() (err error)
- func (d *ThriftTransport) IsOpen() bool
- func (d *ThriftTransport) NextConnection() error
- func (d *ThriftTransport) NextConnectionN(startIndex int) error
- func (d *ThriftTransport) Open() error
- func (d *ThriftTransport) Read(b []byte) (n int, err error)
- func (d *ThriftTransport) RemainingBytes() uint64
- func (d *ThriftTransport) Write(b []byte) (n int, err error)
- type ZkConn
- type ZkConnCreator
- type ZkConnCreatorFunc
Constants ¶
This section is empty.
Variables ¶
var DefaultConfig = &Config{ RandomSource: rand.Reader, Logger: log.DefaultLogger.CreateChild(), }
DefaultConfig is used if any config values are nil
var ErrDuplicateAdvertise = errors.New("service name already advertised")
ErrDuplicateAdvertise is returned by Advertise if users try to Advertise the same service name twice
var ErrNoInstance = errors.New("no thrift instances in disco")
ErrNoInstance is returned by NextConnection if the service has no instances
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 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) Close ¶
func (d *Disco) Close()
Close any open disco connections making this disco unreliable for future updates
func (*Disco) CreatePersistentEphemeralNode ¶
CreatePersistentEphemeralNode creates a persistent ephemeral node
func (*Disco) DeleteAdvertisedService ¶ added in v1.1.6
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) NinjaMode ¶
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,
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) 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
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 ¶
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