balancer

package
v0.13.6-0...-d3ad96a Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 7, 2020 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CustomerBalancer

type CustomerBalancer interface {
	grpc.Balancer
	UpdateLimiter(map[string]int)
}

func LocalFirst

func LocalFirst(service string, ip string, r naming.Resolver, limit map[string]int) CustomerBalancer

LocalFirst returns a Balancer that selects addresses round-robin. It uses r to watch the name resolution updates and updates the addresses available correspondingly.

func RoundRobin

func RoundRobin(service string, r naming.Resolver, limit map[string]int, log *logger.Logger) CustomerBalancer

RoundRobin returns a Balancer that selects addresses round-robin. It uses r to watch the name resolution updates and updates the addresses available correspondingly.

type Limiter

type Limiter struct {
	// contains filtered or unexported fields
}

Limiter 限流组件,用于限制客户端每分钟请求服务器的数量,当超过限制数量时不再选择该服务提供者

func NewLimiter

func NewLimiter(service string, lt map[string]int) *Limiter

NewLimiter 创建限流组件

func (*Limiter) Check

func (m *Limiter) Check(ip string) bool

Check 检查当前服务IP是否达到限流条件

func (*Limiter) Update

func (m *Limiter) Update(lt map[string]int)

Update 更新限流规则

type Resolver

type Resolver struct {
	// contains filtered or unexported fields
}

Resolver 服务解析器,用于解析不同的注册中心地址,创建注册中心watcher

func (*Resolver) Close

func (v *Resolver) Close()

Close 关闭所有watcher

func (*Resolver) Resolve

func (v *Resolver) Resolve(target string) (naming.Watcher, error)

Resolve to resolve the service from zookeeper, target is the dial address of zookeeper target example: "zk://192.168.0.159:2181,192.168.0.154:2181"

type ServiceResolver

type ServiceResolver interface {
	// Resolve creates a Watcher for target.
	Resolve(target string) (naming.Watcher, error)
	Close()
}

func NewResolver

func NewResolver(plat string, server string, service string, timeout time.Duration, sortPrefix string) ServiceResolver

NewResolver 返回服务解析器

type Watcher

type Watcher struct {
	// contains filtered or unexported fields
}

Watcher is the implementaion of grpc.naming.Watcher

func (*Watcher) Close

func (w *Watcher) Close()

Close do nothing

func (*Watcher) Next

func (w *Watcher) Next() ([]*naming.Update, error)

Next 监控服务器地址变化,监控发生异常时移除所有服务,否则等待服务器地址变化

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL