Documentation ¶
Index ¶
- Constants
- Variables
- func HttpAddress(serviceInstance *discovery.ServiceInstance) string
- func InstanceId(serviceInstance *discovery.ServiceInstance) string
- func Spec(serviceInstance *discovery.ServiceInstance) string
- type Discovery
- type DiscoveryBuilder
- type Instances
- type KeyFunc
- type KeyMap
- type Keys
- type Listener
- type ListenerFunc
Constants ¶
const (
DefaultWatchPollInterval = time.Duration(5 * time.Minute)
)
Variables ¶
var ( ErrorNotRunning = errors.New("Discovery client not running") ErrorInvalidWatchPollInterval = errors.New("The WatchPollInterval must be a valid time.Duration or an integral seconds value") )
Functions ¶
func HttpAddress ¶
func HttpAddress(serviceInstance *discovery.ServiceInstance) string
HttpAddress is a KeyFunc which maps a ServiceInstance onto a well-formed http or https URL
func InstanceId ¶
func InstanceId(serviceInstance *discovery.ServiceInstance) string
InstanceId is a KeyFunc which maps a service instance to its unique identifier
func Spec ¶
func Spec(serviceInstance *discovery.ServiceInstance) string
Spec is a KeyFunc which maps a ServiceInstance onto ServiceInstance.Spec()
Types ¶
type Discovery ¶
type Discovery interface { // Connected indicates whether this discovery is actually connected to a zookeeper ensemble Connected() bool // ServiceCount returns the number of watched services in associated with this Discovery ServiceCount() int // ServiceNames returns an independent slice containing the names of the watched services // available in this Discovery ServiceNames() []string // FetchServices returns an Instances containing the set of services with the given name. // If no services by that name are watched, this method returns an error. FetchServices(serviceName string) (Instances, error) // AddListener registers a listener for the given service name. AddListener(serviceName string, listener Listener) // RemoveListener deregisters a listener for the given service name RemoveListener(serviceName string, listener Listener) // BlockUntilConnected blocks until the underlying Curator implementation // is in a connected state with Zookeeper BlockUntilConnected() error // BlockUntilConnectedTimeout is like BlockUntilConnected, except that it will // abort with an error if the specified time elapses without the underlying // Curator implementation transitioning into a connected state. BlockUntilConnectedTimeout(maxWaitTime time.Duration) error // Run starts this Discovery instance. It is idempotent. Run(waitGroup *sync.WaitGroup, shutdown <-chan struct{}) error }
Discovery represents a service discovery endpoint. Instances are created using a DiscoveryBuilder.
type DiscoveryBuilder ¶
type DiscoveryBuilder struct { // Connection is the Curator connection string. It's a comma-delimited // list of zookeeper server nodes Connection string `json:"connection"` // BasePath is the parent znode path for all registrations and watches // for Discovery instances produced by this builder BasePath string `json:"basePath"` // Registrations holds any service instances that are maintained in zookeeper // under the BasePath. Registrations Instances `json:"registrations"` // Watches contains the names of services, registered under the BasePath, // to listen for changes Watches []string `json:"watches"` // WatchPollInterval is the polling interval for any watched services. // Polling is used in addition to setting watches if this value is set. // If this value is not supplied, DefaultWatchPollInterval is used instead. // // This value is ignored if there are no Watches set. WatchPollInterval string `json:"watchPollInterval"` }
DiscoveryBuilder provides a configurable DiscoveryFactory implementation. This type also implements a standard JSON configuration.
type Instances ¶
type Instances []*discovery.ServiceInstance
Instances is a custom slice type that stores ServiceInstances. It also provides a simple API that clients can use when building other data structures.
func (Instances) RegisterWith ¶
func (this Instances) RegisterWith(serviceDiscovery *discovery.ServiceDiscovery) error
RegisterWith registers each instance in this slice with the supplied service discovery. This method normalizes each ServiceInstance, using the discovery API to create a new instance with internal data members set (e.g. timestamps).
func (Instances) String ¶
String outputs a string representation of this Instances, useful for debugging. This method follows pointers to make the debug output more useful.
type KeyFunc ¶
type KeyFunc func(*discovery.ServiceInstance) string
KeyFunc defines the function signature for functions which can map ServiceInstances onto string keys
type KeyMap ¶
type KeyMap map[string]*discovery.ServiceInstance
KeyMap is a convenient map type which can store both the result of a KeyFunc and the associated ServiceInstance
type Keys ¶
type Keys interface {
Add(string)
}
Keys defines the method set for types which can receive the output of a KeyFunc
type Listener ¶
type Listener interface { // ServicesChanged is invoked anytime a Watcher notices that the set of services // with a given name has changed. ServicesChanged(serviceName string, instances Instances) }
Listener receives notifications when the set of watched services has changed.
type ListenerFunc ¶
ListenerFunc is the function type that corresponds to Listener
func (ListenerFunc) ServicesChanged ¶
func (f ListenerFunc) ServicesChanged(serviceName string, instances Instances)