Documentation
¶
Index ¶
Constants ¶
const ( DefaultRefreshInterval = 5 * time.Second DefaultExpireInterval = 15 * time.Second )
Variables ¶
var DefaultLbOpts = Options{ RefreshInterval: DefaultRefreshInterval, ExpireInterval: DefaultExpireInterval, }
Functions ¶
This section is empty.
Types ¶
type BalancerFactory ¶
type BalancerFactory struct {
// contains filtered or unexported fields
}
func NewBalancerFactory ¶
func NewBalancerFactory(config Config) *BalancerFactory
NewBalancerFactory get or create a balancer with given target. If it has the same key(resolver.Target(target)), we will cache and reuse the Balance.
func (*BalancerFactory) GetInstance ¶
type Config ¶
type Config struct {
Resolver discovery.Resolver
Balancer Loadbalancer
LbOpts Options
}
type Loadbalancer ¶
type Loadbalancer interface {
// Pick is used to select an instance according to discovery result
Pick(discovery.Result) discovery.Instance
// Rebalance is used to refresh the cache of load balance's information
Rebalance(discovery.Result)
// Delete is used to delete the cache of load balance's information when it is expired
Delete(string)
// Name returns the name of the Loadbalancer.
Name() string
}
Loadbalancer picks instance for the given service discovery result.
func NewWeightedBalancer ¶
func NewWeightedBalancer() Loadbalancer
NewWeightedBalancer creates a loadbalancer using weighted-random algorithm.
type LoadbalancerCtx ¶ added in v0.10.5
type LoadbalancerCtx interface {
Loadbalancer
// PickCtx selects an instance with access to the request context.
PickCtx(ctx context.Context, req *protocol.Request, e discovery.Result) discovery.Instance
}
LoadbalancerCtx is an optional extension of Loadbalancer that is aware of the per-call context and request. When a Loadbalancer also implements this interface, BalancerFactory.GetInstance prefers PickCtx over Pick so the balancer can make decisions based on ctx values or request fields (e.g. region/zone affinity, tenant routing, header-based stickiness, gray release).
Implementations should fall back to plain Pick semantics when ctx/req carry no relevant information.