zetcd

package
v1.1.6 Latest Latest
Warning

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

Go to latest
Published: Sep 1, 2022 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewRandom

func NewRandom(seed int64) *random

NewRandom returns a load balancer that selects services randomly.

func NewRoundRobin

func NewRoundRobin() *roundRobin

NewRoundRobin returns a load balancer that returns services in sequence.

Types

type Balancer

type Balancer interface {
	GetPoint(count int) (int, error)
}

Balancer 平衡模式

type Etcd added in v1.1.0

type Etcd struct {
	Hosts         []string
	DialTimeout   int64
	DialKeepalive int64
}

func (*Etcd) SetDialKeepAlive added in v1.1.2

func (z *Etcd) SetDialKeepAlive(dialKeepAlive int64) *Etcd

SetDialKeepAlive 设置keepalive时间

func (*Etcd) SetDialTimeout added in v1.1.2

func (z *Etcd) SetDialTimeout(dialTimeout int64) *Etcd

SetDialTimeout 设置超时时间

type EtcdDis

type EtcdDis struct {
	Cluster string
	Etcd    *Etcd //etcd服务集群机器
	//注册; key:服务名称
	MapRegister map[string]*EtcdService //["Cluster/server.name:Kind"]*EtcdService
	//监听相关的服务
	MapWatch map[string]*EtcdMaster //[service_name]*EtcdService
	Logger   *logrus.Logger
	sync.RWMutex
}

func NewEtcdDis

func NewEtcdDis(cluster string, etcd *Etcd, logger *logrus.Logger) *EtcdDis

NewEtcdDis 注册相关的函数

func (*EtcdDis) GetGrpcServiceInfoRandom added in v1.1.0

func (d *EtcdDis) GetGrpcServiceInfoRandom(service string) (*ValueInfo, bool)

GetGrpcServiceInfoRandom 获取服务grpc节点信息-随机获取

func (*EtcdDis) GetServiceInfoAllNode

func (d *EtcdDis) GetServiceInfoAllNode(service string) ([]EtcdNode, bool)

GetServiceInfoAllNode 获取服务的节点信息

func (*EtcdDis) IsWatched

func (d *EtcdDis) IsWatched(service string) bool

func (*EtcdDis) Register

func (d *EtcdDis) Register(keyInfo *KeyInfo, valueInfo *ValueInfo, retry bool)

func (*EtcdDis) Watch

func (d *EtcdDis) Watch(service string)

监听相关的

type EtcdMaster

type EtcdMaster struct {
	Cluster string
	Etcd    *Etcd
	Service string               //路径
	Nodes   map[string]*EtcdNode //[grpc]*EtcdNode

	State bool
	Loger *logrus.Logger
	sync.Mutex
	// contains filtered or unexported fields
}

func NewMaster

func NewMaster(cluster, service string, etcd *Etcd, logger *logrus.Logger) (*EtcdMaster, error)

func (*EtcdMaster) Close added in v1.1.0

func (m *EtcdMaster) Close()

func (*EtcdMaster) DecodeKeyValue added in v1.1.0

func (m *EtcdMaster) DecodeKeyValue(ev *mvccpb.KeyValue) (*KeyInfo, *ValueInfo, error)

func (*EtcdMaster) DoWatch added in v1.1.0

func (m *EtcdMaster) DoWatch()

func (*EtcdMaster) Get added in v1.1.0

func (m *EtcdMaster) Get()

func (*EtcdMaster) GetAllNodes

func (m *EtcdMaster) GetAllNodes() []EtcdNode

func (*EtcdMaster) GetGrpcNodeRandom added in v1.1.0

func (m *EtcdMaster) GetGrpcNodeRandom() (*ValueInfo, bool)

func (*EtcdMaster) GetKeyInfo

func (m *EtcdMaster) GetKeyInfo(key []byte) (*KeyInfo, error)

func (*EtcdMaster) GetPrefixPath added in v1.1.0

func (m *EtcdMaster) GetPrefixPath() string

func (*EtcdMaster) GetValueInfo

func (m *EtcdMaster) GetValueInfo(value []byte) (*ValueInfo, error)

func (*EtcdMaster) NewEtcdNodes added in v1.1.0

func (m *EtcdMaster) NewEtcdNodes(state bool, keyInfo *KeyInfo) *EtcdNode

func (*EtcdMaster) ReBuildNode added in v1.1.0

func (m *EtcdMaster) ReBuildNode(keyInfo *KeyInfo)

func (*EtcdMaster) Stop added in v1.1.0

func (m *EtcdMaster) Stop()

func (*EtcdMaster) Watch added in v1.1.0

func (m *EtcdMaster) Watch()

type EtcdNode

type EtcdNode struct {
	State bool
	*KeyInfo
	EndPoints map[string]*ValueInfo //[ip:port]ValueInfo
	sync.Mutex
}

EtcdNode etcd注册的节点

func (*EtcdNode) GetEndPointRandom added in v1.1.0

func (n *EtcdNode) GetEndPointRandom() (*ValueInfo, bool)

type EtcdService

type EtcdService struct {
	Key   *KeyInfo
	Value *ValueInfo
	Retry bool
	// contains filtered or unexported fields
}

func NewEtcdService

func NewEtcdService(etcd *Etcd, keyinfo *KeyInfo, valueInfo *ValueInfo, retry bool, log *logrus.Logger) (*EtcdService, error)

func (*EtcdService) GetInfo added in v1.1.0

func (s *EtcdService) GetInfo() ([]*mvccpb.KeyValue, error)

func (*EtcdService) KeepLive

func (s *EtcdService) KeepLive() (<-chan *clientv3.LeaseKeepAliveResponse, error)

KeepLive 用于维持租约

func (*EtcdService) ReStart

func (s *EtcdService) ReStart() error

func (*EtcdService) Revoke

func (s *EtcdService) Revoke()

revoke 撤销一个租约

func (*EtcdService) Start

func (s *EtcdService) Start() error

Start 启动

func (*EtcdService) Stop

func (s *EtcdService) Stop()

Stop 停止

func (*EtcdService) UpdateService

func (s *EtcdService) UpdateService(status STATUS, requestFlow uint32) error

type Hub

type Hub struct {
	Etcd *Etcd
	// contains filtered or unexported fields
}

func NewHub

func NewHub(etcd *Etcd) (*Hub, error)

func (*Hub) AddEtcdServerAddress

func (z *Hub) AddEtcdServerAddress(addr []string)

AddEtcdServerAddress 添加etcd服务地址

func (*Hub) GetAll

func (z *Hub) GetAll(key string) (*[]string, error)

func (*Hub) GetClient

func (z *Hub) GetClient() *clientv3.Client

func (*Hub) GetOne

func (z *Hub) GetOne(key string, balance Balancer) (string, error)

func (*Hub) SetEtcdServerAddress

func (z *Hub) SetEtcdServerAddress(etcdHosts []string)

SetEtcdServerAddress 设置etcd服务地址

type KeyInfo

type KeyInfo struct {
	Cluster string //集群
	Name    string //服务名称
	Kind    string //grpc,http
}

func NewKeyInfo

func NewKeyInfo(cluster, name, kind string) *KeyInfo

func (*KeyInfo) GetName added in v1.1.0

func (i *KeyInfo) GetName() string

GetName 获取名称

func (*KeyInfo) GetNameKind

func (i *KeyInfo) GetNameKind() string

func (*KeyInfo) GetRegisterKey

func (i *KeyInfo) GetRegisterKey() string

func (*KeyInfo) SetRegisterKey

func (i *KeyInfo) SetRegisterKey(address string) error

SetRegisterKey 设置注册地址

type STATUS

type STATUS int

STATUS 0 初始化, 1 正常服务, 2,挂起, 3, 主动关闭 500 异常情况

const StatusClose STATUS = 3
const StatusConnectError STATUS = 500
const StatusEtcdRemoteCloseError STATUS = 505
const StatusGrantError STATUS = 501
const StatusHang STATUS = 2
const StatusInit STATUS = 0
const StatusKeepaliveError STATUS = 503
const StatusOk STATUS = 1
const StatusPutError STATUS = 502
const StatusRevokeError STATUS = 504

type ValueInfo

type ValueInfo struct {
	Kind        string //grpc,http
	Ip          string //服务注册ip
	Port        uint32 //服务注册端口
	Status      STATUS //0 初始化, 1 正常 , 2 挂起, 3关闭
	RequestFlow uint32
	UpdatedAt   int64
}

func NewValueInfo

func NewValueInfo(kind, ip string, port uint32, status STATUS, requestFlow uint32, updatedAt int64) *ValueInfo

func (*ValueInfo) DecodeValue

func (i *ValueInfo) DecodeValue(infoByte []byte) error

DecodeValue 解码 proto消息

func (*ValueInfo) EncodeValue

func (i *ValueInfo) EncodeValue() ([]byte, error)

EncodeValue 编码 proto消息

func (*ValueInfo) GetValidAddress

func (i *ValueInfo) GetValidAddress() (string, bool)

func (*ValueInfo) SetRegisterAddress

func (i *ValueInfo) SetRegisterAddress(address string) error

SetRegisterAddress 设置服务地址 ip:port

Jump to

Keyboard shortcuts

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