client

package
v0.0.0-...-7ae5dd8 Latest Latest
Warning

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

Go to latest
Published: Apr 30, 2024 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type EtcdClient

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

func NewEtcdClient

func NewEtcdClient(ctx context.Context, endpoints []string, user, pass string) (*EtcdClient, error)

func (*EtcdClient) Discovery

func (e *EtcdClient) Discovery(ctx context.Context, path string, event chan *serviceregdisc.DiscoverEvent)

Discovery 服务发现 第一次先用前缀key主动获取一次服务信息 之后用watch监视前缀key,监视数据变化更新服务信息

func (*EtcdClient) Register

func (e *EtcdClient) Register(ctx context.Context, path string, data []byte) error

Register 服务注册 path 注册路径, data节点数据 example: path: /cc/service/endpoint/user/192.168.2.1 path作为数据存储key,带租约存储数据,定时续期,续期的相当于心跳的作用,服务失效了,租约过期,数据会被删除,节点信息也就不存在了

type ZKClient

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

func NewZKClient

func NewZKClient(host []string, user, pass string) (*ZKClient, error)

NewZKClient host []string{"192.168.1.2:2181", "192.168.1.3:2181"}

func (*ZKClient) Discovery

func (zkc *ZKClient) Discovery(ctx context.Context, path string, event chan *serviceregdisc.DiscoverEvent)

Discovery 服务发现 添加一个watch,当服务信息发生变化时重新获取 服务器信息通过chan传递

func (*ZKClient) Register

func (zkc *ZKClient) Register(ctx context.Context, path string, data []byte) error

Register 注册节点 example: path: /cc/service/endpoint/user/192.168.2.1 先创建节点/cc/service/endpoint/user,再创建临时节点/cc/service/endpoint/user/192.168.2.1 服务信息创建临时节点的作用是如果服务不可用了,会话超时被销毁,注册的节点也会被销毁,起到了监控服务存活的目的 CreateProtectedEphemeralSequential 是创建受保护的临时顺序节点,作用是如果服务器崩溃了,重连到其他服务器可以继续保持前一个服务器的会话

Jump to

Keyboard shortcuts

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