Documentation ¶
Overview ¶
Package sd, provide base implementation of discovery.Client and discovery.Instancer.
Index ¶
- Constants
- func NewSimpleServiceCache() discovery.ServiceCache
- type CachedInstancer
- func (i *CachedInstancer) DeregisterCallback(id interface{})
- func (i *CachedInstancer) Instances(matcher discovery.InstanceMatcher) (ret []*discovery.Instance, err error)
- func (i *CachedInstancer) RefreshNow(ctx context.Context) (*discovery.Service, error)
- func (i *CachedInstancer) RegisterCallback(id interface{}, cb discovery.Callback)
- func (i *CachedInstancer) Service() (svc *discovery.Service)
- func (i *CachedInstancer) ServiceName() string
- func (i *CachedInstancer) Start(ctx context.Context)
- func (i *CachedInstancer) Stop()
- type CachedInstancerOption
- type CachedInstancerOptions
- type InstancerOption
- type RefreshFunc
Constants ¶
const (
DefaultRefreshBackoffFactor float64 = 1.5
)
Variables ¶
This section is empty.
Functions ¶
func NewSimpleServiceCache ¶
func NewSimpleServiceCache() discovery.ServiceCache
NewSimpleServiceCache returns a ServiceCache with map[string]*Service as a back storage This ServiceCache is not goroutine-safe
Types ¶
type CachedInstancer ¶
type CachedInstancer struct { CachedInstancerOption // contains filtered or unexported fields }
CachedInstancer implements discovery.Instancer CachedInstancer provides common implementation of discovery.Instancer with an internal cache and a background goroutine to periodically refresh service cache using provided RefreshFunc. See discovery.Instancer
func MakeCachedInstancer ¶
func MakeCachedInstancer(opts ...CachedInstancerOptions) CachedInstancer
MakeCachedInstancer returns a CachedInstancer that provide basic implementation of discovery.Instancer See discovery.Instancer
func (*CachedInstancer) DeregisterCallback ¶
func (i *CachedInstancer) DeregisterCallback(id interface{})
func (*CachedInstancer) Instances ¶
func (i *CachedInstancer) Instances(matcher discovery.InstanceMatcher) (ret []*discovery.Instance, err error)
Instances implements discovery.Instancer
func (*CachedInstancer) RefreshNow ¶
RefreshNow invoke refresh task immediately in current goroutine. Note: refresh function is run in current goroutine
func (*CachedInstancer) RegisterCallback ¶
func (i *CachedInstancer) RegisterCallback(id interface{}, cb discovery.Callback)
func (*CachedInstancer) Service ¶
func (i *CachedInstancer) Service() (svc *discovery.Service)
Service implements discovery.Instancer
func (*CachedInstancer) ServiceName ¶
func (i *CachedInstancer) ServiceName() string
ServiceName implements discovery.Instancer
func (*CachedInstancer) Start ¶
func (i *CachedInstancer) Start(ctx context.Context)
func (*CachedInstancer) Stop ¶
func (i *CachedInstancer) Stop()
Stop implements discovery.Instancer.
type CachedInstancerOption ¶
type CachedInstancerOption struct { InstancerOption // BackgroundRefreshFunc is used for background cache refresh. // This function is repeated in a loop.Loop, so following behavior is guaranteed: // - Sequential execution is guaranteed, no concurrent conditions between execution need to considered. // - Next execution is not scheduled until current execution finishes. So this function can block current goroutine. // The repeat interval is configurable via InstancerOption.RefresherOptions BackgroundRefreshFunc RefreshFunc // ForegroundRefreshFunc is used for foreground cache refresh, directly invoked via CachedInstancer.RefreshNow. // This function always invoked in current goroutine. So concurrent conditions need to be considered, // and cancellation/timeout need to be taken care of ForegroundRefreshFunc RefreshFunc }
type CachedInstancerOptions ¶
type CachedInstancerOptions func(opt *CachedInstancerOption)
CachedInstancerOptions used to create CachedInstancer
type InstancerOption ¶
type InstancerOption struct { // Name service name Name string // Logger logger to use for Logger log.ContextualLogger // Verbose whether to create logs for internal state changes Verbose bool // RefresherOptions controls how service refresher to retry refreshing attempt in case of failure. // Default is loop.ExponentialRepeatIntervalOnError with initial interval 50ms and factor 1.5 RefresherOptions []loop.TaskOptions }
InstancerOption general options applicable to any cache based instancer implementation