rpc

package
v0.0.0-...-d2a9b45 Latest Latest
Warning

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

Go to latest
Published: Oct 14, 2020 License: Apache-2.0 Imports: 8 Imported by: 0

README

Example


//新建Register
reg := &rpc.Register{
    Servers:       []string{"127.0.0.1:2181"},
    BasePath:      "/rpc_v2",
    FlushDuration: 5 * time.Second,
}

//启动
reg.Run()

//注册节点
cb = func(operator rpc.OptType, service, address string, err error) {
    //此回调函数会在注册出错时调用
    //do something
}
AddServer(service, fmt.Sprintf("%s:%d", podIP, port), cb)

//删除节点
cb2 = func(operator rpc.OptType, service, address string, err error) {
    //此回调函数会在注册出错时调用
    //do something
}
DelServer(service, fmt.Sprintf("%s:%d", podIP, port), cb2)

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type OptType

type OptType int
const (
	OptDelete OptType = iota
	OptAdd
	OptSet
	OptCreate
)

type Register

type Register struct {
	Servers  []string
	BasePath string
	QPS      float64 // Qps用于限制写入zookeeper的速度
	// contains filtered or unexported fields
}

func (*Register) Add

func (reg *Register) Add(service, addr string) error

Add 函数负责将新的节点注册到指定service下

func (*Register) Delete

func (reg *Register) Delete(service, addr string) error

Delete 函数负责从指定service删除节点

func (*Register) Init

func (reg *Register) Init() error

func (*Register) Update

func (reg *Register) Update(service string, servers []string) error

Update 函数一般在程序初始化时调用,或者在定时器中调用。 作用是强制刷新指定service注册的所有节点IP,防止丢失Pod变更事件,导致 已服务的节点信息没有及时刷新。

Jump to

Keyboard shortcuts

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