common

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Jul 29, 2022 License: MIT, Apache-2.0, BSD-2-Clause, + 4 more Imports: 22 Imported by: 0

Documentation

Index

Constants

View Source
const (
	OpKeyRegisterInstance      = "RegisterInstance"
	OpKeyDeregisterInstance    = "DeregisterInstance"
	OpKeyInstanceHeartbeat     = "InstanceHeartbeat"
	OpKeyDiscover              = "Discover"
	OpKeyReportClient          = "ReportClient"
	OpKeyRateLimitInit         = "RateLimitInit"
	OpKeyRateLimitAcquire      = "RateLimitAcquire"
	OpKeyRateLimitMetricInit   = "RateLimitMetricInit"
	OpKeyRateLimitMetricReport = "RateLimitMetricReport"
	OpKeyGetConfigFile         = "GetConfigFile"
	OpKeyWatchConfigFiles      = "WatchConfigFiles"
)

Variables

This section is empty.

Functions

func CreateHeaderContext

func CreateHeaderContext(timeout time.Duration, headers map[string]string) (context.Context, context.CancelFunc)

创建传输grpc头的valueContext

func CreateHeaderContextWithReqId

func CreateHeaderContextWithReqId(timeout time.Duration, reqID string) (context.Context, context.CancelFunc)

创建传输grpc头的valueContext

func DeregisterRequestToProto

func DeregisterRequestToProto(request *model.InstanceDeRegisterRequest) (pbInstance *namingpb.Instance)

将用户反注册请求转化为服务端需要的proto

func GetConnErrorCode

func GetConnErrorCode(err error) int32

获取连接错误码

func GetUpdateTaskRequestTime

func GetUpdateTaskRequestTime(updateTask *serviceUpdateTask) time.Duration

获取一个updateTask的请求更新时间

func HeartbeatRequestToProto

func HeartbeatRequestToProto(request *model.InstanceHeartbeatRequest) (pbInstance *namingpb.Instance)

将用户心跳请转化为服务端需要的proto

func NetworkError

func NetworkError(connManager network.ConnectionManager, conn *network.Connection,
	errCode int32, err error, startTime time.Time, msg string) model.SDKError

返回网络错误,并回收连接

func NextDeRegisterInstanceReqID

func NextDeRegisterInstanceReqID() string

生成RegisterService调用的请求Id

func NextDiscoverReqID

func NextDiscoverReqID() string

生成GetInstances调用的请求Id

func NextGetConfigFileReqID

func NextGetConfigFileReqID() string

生成GetConfigFile调用的请求Id

func NextHeartbeatReqID

func NextHeartbeatReqID() string

生成RegisterService调用的请求Id

func NextRateLimitAcquireReqID

func NextRateLimitAcquireReqID() string

生成RateLimit配额获取调用的请求Id

func NextRateLimitInitReqID

func NextRateLimitInitReqID() string

生成RateLimit初始化调用的请求Id

func NextRegisterInstanceReqID

func NextRegisterInstanceReqID() string

生成RegisterService调用的请求Id

func NextReportClientReqID

func NextReportClientReqID() string

生成ReportClient调用的请求Id

func NextWatchConfigFilesReqID

func NextWatchConfigFilesReqID() string

生成WatchConfigFiles调用的请求Id

func RegisterRequestToProto

func RegisterRequestToProto(request *model.InstanceRegisterRequest) (pbInstance *namingpb.Instance)

将用户的API注册请求结构转换成为server端需要的proto结构

func ReportClientRequestToProto

func ReportClientRequestToProto(request *model.ReportClientRequest) (pbInstance *namingpb.Client)

将客户端上报请转化为服务端需要的proto

Types

type ClientFailEvent

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

ClientFailEvent 用于recv协程通知send协程关于链路故障的问题

type DiscoverClient

type DiscoverClient interface {
	// 发送服务发现请求
	Send(*namingpb.DiscoverRequest) error
	// 接收服务发现应答
	Recv() (*namingpb.DiscoverResponse, error)
	// 发送EOF
	CloseSend() error
}

服务发现客户端接口

type DiscoverClientCreator

type DiscoverClientCreator func(
	reqId string, connection *network.Connection, timeout time.Duration) (DiscoverClient, context.CancelFunc, error)

创建client的函数

type DiscoverConnector

type DiscoverConnector struct {
	*common.RunContext
	ServiceConnector *plugin.PluginBase
	// contains filtered or unexported fields
}

DiscoverConnector cl5服务端代理,使用GRPC协议对接

func (*DiscoverConnector) DeRegisterServiceHandler

func (g *DiscoverConnector) DeRegisterServiceHandler(key *model.ServiceEventKey) error

DeRegisterServiceHandler 反注册事件监听器 异常场景:当sdk已经退出过程中,则返回error

func (*DiscoverConnector) Destroy

func (g *DiscoverConnector) Destroy() error

Destroy 销毁插件,可用于释放资源

func (*DiscoverConnector) Init

func (g *DiscoverConnector) Init(ctx *plugin.InitContext, createClient DiscoverClientCreator)

Init 初始化插件

func (*DiscoverConnector) RegisterServiceHandler

func (g *DiscoverConnector) RegisterServiceHandler(svcEventHandler *serverconnector.ServiceEventHandler) error

RegisterServiceHandler 注册服务监听器 异常场景:当key不合法或者sdk已经退出过程中,则返回error

func (*DiscoverConnector) StartUpdateRoutines

func (g *DiscoverConnector) StartUpdateRoutines()

StartUpdateRoutines 初始化connector调度主协程

func (*DiscoverConnector) UpdateServers

func (g *DiscoverConnector) UpdateServers(key *model.ServiceEventKey) error

UpdateServers 更新服务端地址 异常场景:当地址列表为空,或者地址全部连接失败,则返回error,调用者需进行重试

type StreamingClient

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

StreamingClient 流式客户端,带连接

func (*StreamingClient) CloseStream

func (s *StreamingClient) CloseStream(closeSend bool) bool

CloseStream 关闭流并释放连接

func (*StreamingClient) IsEndStream

func (s *StreamingClient) IsEndStream() bool

IsEndStream 设置流关闭

Jump to

Keyboard shortcuts

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