Documentation
¶
Index ¶
Constants ¶
const ( // DefaultCheckMethod xx DefaultCheckMethod = 0 // DefaultCheckTimeout xx DefaultCheckTimeout = 2 // DefaultCheckMaxErrNum xx DefaultCheckMaxErrNum = 2 // DefaultCheckInterval xx DefaultCheckInterval = 5 )
default check setting
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type CheckConf ¶
type CheckConf struct {
// contains filtered or unexported fields
}
CheckConf 客户端服务发现负载均衡配置
func NewCheckConf ¶
NewCheckConf 创建主动探测的负载均衡配置 CheckConf
func (*CheckConf) NotifyAllObservers ¶
func (s *CheckConf) NotifyAllObservers()
NotifyAllObservers 通知所有的
func (*CheckConf) UpdateConf ¶
UpdateConf 更新配置时,通知监听者也更新
type Conf ¶
type Conf interface { Attach(o Observer) // 绑定 GetConf() []string // 获取配置 WatchConf() // 监听 UpdateConf(conf []string) // 更新 }
Conf 服务发现配置主题
type ConsistentHashBanlance ¶
type ConsistentHashBanlance struct {
// contains filtered or unexported fields
}
ConsistentHashBanlance 一致性Hash负载均衡
func NewConsistentHashBanlance ¶
func NewConsistentHashBanlance(replicas int, fn Hash) *ConsistentHashBanlance
NewConsistentHashBanlance 创建
func (*ConsistentHashBanlance) Add ¶
func (c *ConsistentHashBanlance) Add(params ...string) error
Add 方法用来添加缓存节点,参数为节点 key,比如使用 IP
func (*ConsistentHashBanlance) Get ¶
func (c *ConsistentHashBanlance) Get(key string) (string, error)
Get 方法根据给定的对象获取最靠近它的那个节点
func (*ConsistentHashBanlance) IsEmpty ¶
func (c *ConsistentHashBanlance) IsEmpty() bool
IsEmpty 验证是否为空
func (*ConsistentHashBanlance) SetConf ¶
func (c *ConsistentHashBanlance) SetConf(conf Conf)
SetConf 设置
func (*ConsistentHashBanlance) Update ¶
func (c *ConsistentHashBanlance) Update()
Update 更新配置,通知其他...
type LoadBalance ¶
LoadBalance 负载均衡策略接口
func FactorWithConf ¶
func FactorWithConf(lbType LbType, mConf Conf) LoadBalance
FactorWithConf 观察者模式结合负载均衡器工厂方法
type LoadBalanceObserver ¶
type LoadBalanceObserver struct {
ModuleConf *ZKConf
}
LoadBalanceObserver 观察者
func NewLoadBalanceObserver ¶
func NewLoadBalanceObserver(conf *ZKConf) *LoadBalanceObserver
NewLoadBalanceObserver 创建 NewLoadBalanceObserver
type RandomBalance ¶
type RandomBalance struct {
// contains filtered or unexported fields
}
RandomBalance 存放服务器列表和当前使用服务器下标
type RoundRobinBalance ¶
type RoundRobinBalance struct {
// contains filtered or unexported fields
}
RoundRobinBalance 轮询负载均衡
func (*RoundRobinBalance) Add ¶
func (r *RoundRobinBalance) Add(params ...string) error
Add 添加服务 一次添加一个服务地址
type WeightNode ¶
type WeightNode struct { Weight int // 权重 // contains filtered or unexported fields }
WeightNode 权重节点
type WeightRoundRobinBalance ¶
type WeightRoundRobinBalance struct {
// contains filtered or unexported fields
}
WeightRoundRobinBalance 加权轮询
func (*WeightRoundRobinBalance) Add ¶
func (r *WeightRoundRobinBalance) Add(params ...string) error
Add 添加下游服务 params 接收两个string参数 第一个为服务器Ip 第二个是该服务节点权重值
func (*WeightRoundRobinBalance) Get ¶
func (r *WeightRoundRobinBalance) Get(key string) (string, error)
Get Next方法的进一步包装
func (*WeightRoundRobinBalance) Next ¶
func (r *WeightRoundRobinBalance) Next() string
Next 加权获取下游服务
func (*WeightRoundRobinBalance) SetConf ¶
func (r *WeightRoundRobinBalance) SetConf(conf Conf)
SetConf 设置服务发现
func (*WeightRoundRobinBalance) Update ¶
func (r *WeightRoundRobinBalance) Update()
Update 更新,通知其他...
type ZKConf ¶
type ZKConf struct { Observers []Observer // 观察者列表 // contains filtered or unexported fields }
ZKConf zookeeper 客户端服务发现配置
func NewLoadBalanceZkConf ¶
func NewLoadBalanceZkConf( format, path string, zkHosts []string, conf map[string]string) (*ZKConf, error)
NewLoadBalanceZkConf 创建 ZKConf
func (*ZKConf) NotifyAllObservers ¶
func (s *ZKConf) NotifyAllObservers()
NotifyAllObservers 通知所有的 Observer