register

package module
v0.0.0-...-afa0874 Latest Latest
Warning

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

Go to latest
Published: Mar 22, 2024 License: MIT Imports: 25 Imported by: 1

Documentation

Index

Constants

View Source
const (
	GRPC                  string = "grpc"
	HTTP                         = "http"
	SUCCESS                      = "success"
	MEMBERLIST_PREFIX_KEY        = "node:"
	SERVERBASE_PREFIX_KEY        = "serverbase:"
	VERSION                      = "version"
	METADATA_PREFIX_KEY          = "metadata:"
)

Variables

View Source
var File_register_proto protoreflect.FileDescriptor
View Source
var ServerRegisterService_ServiceDesc = grpc.ServiceDesc{
	ServiceName: "register.ServerRegisterService",
	HandlerType: (*ServerRegisterServiceServer)(nil),
	Methods: []grpc.MethodDesc{
		{
			MethodName: "RegisterServerBase",
			Handler:    _ServerRegisterService_RegisterServerBase_Handler,
		},
		{
			MethodName: "ReceivePing",
			Handler:    _ServerRegisterService_ReceivePing_Handler,
		},
	},
	Streams:  []grpc.StreamDesc{},
	Metadata: "register.proto",
}

ServerRegisterService_ServiceDesc is the grpc.ServiceDesc for ServerRegisterService service. It's only intended for direct use with grpc.RegisterService, and not to be introspected or modified (even as a copy)

Functions

func NewNotify

func NewNotify(option *NotifyOption, datasource *redis.Client) (*notify, error)

NewNotify

@Description: 新建通知
@return *notify

func RegisterServerRegisterServiceServer

func RegisterServerRegisterServiceServer(s grpc.ServiceRegistrar, srv ServerRegisterServiceServer)

Types

type Empty

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

func (*Empty) Descriptor deprecated

func (*Empty) Descriptor() ([]byte, []int)

Deprecated: Use Empty.ProtoReflect.Descriptor instead.

func (*Empty) ProtoMessage

func (*Empty) ProtoMessage()

func (*Empty) ProtoReflect

func (x *Empty) ProtoReflect() protoreflect.Message

func (*Empty) Reset

func (x *Empty) Reset()

func (*Empty) String

func (x *Empty) String() string

type InstanceEvent

type InstanceEvent interface {
	// 添加实例事件
	AddServerInstance(id InstanceId, sb *ServerBase)
	// 移除实例事件
	DeleteServerInstance(id InstanceId, sb *ServerBase)
	// 清空实例事件
	ClearServerInstance(id InstanceId, sb *ServerBase)
}

事件通知

type InstanceId

type InstanceId string

实例ID

func NewInstanceId

func NewInstanceId(serviceId, addr string) InstanceId

NewInstanceId

@Description: 新建实例ID
@param serviceId
@param addr
@return string

func (InstanceId) GetAddr

func (s InstanceId) GetAddr() string

GetAddr

@Description: 获取远程地址
@receiver this
@return string

func (InstanceId) GetServiceId

func (s InstanceId) GetServiceId() string

GetServiceId

@Description: 获取业务ID
@receiver this
@return string

func (InstanceId) Split

func (s InstanceId) Split() (string, string)

Split

@Description: 服务实例ID信息拆分
@receiver this
@return string
@return string

func (InstanceId) ToString

func (s InstanceId) ToString() string

ToString

@Description: 实例ID转字符串
@receiver s
@return string

type NotifyOption

type NotifyOption struct {
	ServerId string   //服务ID
	Port     int      //当前服务地址
	Members  []string //集群成员链接地址
	// contains filtered or unexported fields
}

notify @Description: 通知组件

type Options

type Options struct {
	RedisOption *redis.Options
	GlobalTime  int
	MemberPort  int
}

type RegisterBody

type RegisterBody struct {
	ServiceId       string `protobuf:"bytes,1,opt,name=serviceId,proto3" json:"serviceId,omitempty"`
	RemoteAddr      string `protobuf:"bytes,2,opt,name=remoteAddr,proto3" json:"remoteAddr,omitempty"`
	ServerType      string `protobuf:"bytes,3,opt,name=serverType,proto3" json:"serverType,omitempty"`
	HealthPath      string `protobuf:"bytes,4,opt,name=healthPath,proto3" json:"healthPath,omitempty"`
	HealthyInterval uint32 `protobuf:"varint,5,opt,name=healthyInterval,proto3" json:"healthyInterval,omitempty"`
	RegisterType    uint32 `protobuf:"varint,6,opt,name=registerType,proto3" json:"registerType,omitempty"`
	KeepPrefix      bool   `protobuf:"varint,7,opt,name=keepPrefix,proto3" json:"keepPrefix,omitempty"`
	LoadType        uint32 `protobuf:"varint,8,opt,name=loadType,proto3" json:"loadType,omitempty"`
	Private         bool   `protobuf:"varint,9,opt,name=private,proto3" json:"private,omitempty"`
	// contains filtered or unexported fields
}

func (*RegisterBody) Descriptor deprecated

func (*RegisterBody) Descriptor() ([]byte, []int)

Deprecated: Use RegisterBody.ProtoReflect.Descriptor instead.

func (*RegisterBody) GetHealthPath

func (x *RegisterBody) GetHealthPath() string

func (*RegisterBody) GetHealthyInterval

func (x *RegisterBody) GetHealthyInterval() uint32

func (*RegisterBody) GetKeepPrefix

func (x *RegisterBody) GetKeepPrefix() bool

func (*RegisterBody) GetLoadType

func (x *RegisterBody) GetLoadType() uint32

func (*RegisterBody) GetPrivate

func (x *RegisterBody) GetPrivate() bool

func (*RegisterBody) GetRegisterType

func (x *RegisterBody) GetRegisterType() uint32

func (*RegisterBody) GetRemoteAddr

func (x *RegisterBody) GetRemoteAddr() string

func (*RegisterBody) GetServerType

func (x *RegisterBody) GetServerType() string

func (*RegisterBody) GetServiceId

func (x *RegisterBody) GetServiceId() string

func (*RegisterBody) ProtoMessage

func (*RegisterBody) ProtoMessage()

func (*RegisterBody) ProtoReflect

func (x *RegisterBody) ProtoReflect() protoreflect.Message

func (*RegisterBody) Reset

func (x *RegisterBody) Reset()

func (*RegisterBody) String

func (x *RegisterBody) String() string

type RegisterCenter

type RegisterCenter struct {
	UnimplementedServerRegisterServiceServer
	// contains filtered or unexported fields
}

服务注册中心组件

func GetRegisterCenter

func GetRegisterCenter(serverId string) *RegisterCenter

GetRegisterCenter

@Description: 获取注册中心
@param serverId
@return *RegisterCenter

func NewRegisterCenter

func NewRegisterCenter(ctx context.Context, option *Options) (*RegisterCenter, error)

NewRegisterCenter

@Description: 新建注册中心
@param ctx
@param globalTime 全局健康检查定时调度间隔
@param option redis数据源配置项
@return *RegisterCenter
@return error

func (*RegisterCenter) AddMetadata

func (s *RegisterCenter) AddMetadata(serviceId, prefix string, data map[string]string) error

AddMetadata

@Description: 添加元数据
@receiver s
@param serviceId 业务ID
@param prefix 元数据前缀
@param data
@return error

func (*RegisterCenter) AddServerBase

func (s *RegisterCenter) AddServerBase(registerType, healthyInterval, loadType int, healthPath, serverType, serviceId, remoteAddr string, keepPrefix, private bool) (*ServerBase, error)

AddServerBase

@Description: 添加服务实例
@receiver s
@param registerType 注册类型 0 临时 1 长期  临时类型健康检查异常会移除实例,长期类型则会给实例标记为不健康但不会移除
@param healthyInterval 健康心跳间隔时间 单位秒 默认是5秒
@param healthPath 主动健康检查地址
@param serverType 服务类型 grpc/http
@param serviceId 业务id
@param remoteAddr 远程地址
@return *ServerBase
@return error

func (*RegisterCenter) ClearMetadata

func (s *RegisterCenter) ClearMetadata(serviceId, prefix string) error

ClearMetadata

@Description: 清空元数据
@receiver s
@param serviceId
@param prefix
@return error

func (*RegisterCenter) Close

func (s *RegisterCenter) Close()

Close

@Description: 关闭注册中心
@receiver s

func (*RegisterCenter) DeleteServerBase

func (s *RegisterCenter) DeleteServerBase(instanceId InstanceId) error

DeleteServerBase

@Description: 移除基础服务实例
@receiver s
@param instanceId 实例id
@return error

func (*RegisterCenter) ExistServiceId

func (s *RegisterCenter) ExistServiceId(serviceId string) bool

ExistServiceId

@Description: 业务ID是否存在
@receiver s
@param serviceId
@return bool

func (*RegisterCenter) GetAllMetadata

func (s *RegisterCenter) GetAllMetadata(serviceId, prefix string) (map[string]string, error)

GetAllMetadata

@Description: 获取全部元数据
@receiver s
@param serviceId
@param prefix
@return map[string]string
@return error

func (*RegisterCenter) GetMetadata

func (s *RegisterCenter) GetMetadata(serviceId, prefix, metadataKey string) (string, error)

GetMetadata

@Description: 获取指定元数据
@receiver s
@param serviceId
@param prefix
@param metadataKey
@return string
@return error

func (*RegisterCenter) GetServerBase

func (s *RegisterCenter) GetServerBase(instanceId InstanceId) *ServerBase

GetServerBase

@Description: 获取服务实例
@receiver s
@param instanceId
@return *ServerBase

func (*RegisterCenter) GetServerBases

func (s *RegisterCenter) GetServerBases(serviceId string) []*ServerBase

GetServerBases

@Description: 获取服务实例数组
@receiver s
@param serviceId
@return []*ServerBase

func (*RegisterCenter) HttpReceivePing

func (s *RegisterCenter) HttpReceivePing(w http.ResponseWriter, r *http.Request)

HttpReceivePing

@Description: 接收ping心跳Http接口
@param w
@param r

func (*RegisterCenter) HttpRegisterServerBase

func (s *RegisterCenter) HttpRegisterServerBase(w http.ResponseWriter, r *http.Request)

HttpRegisterServerBase

@Description: 服务注册http接口
@param w
@param r

func (*RegisterCenter) ReceivePing

func (s *RegisterCenter) ReceivePing(ctx context.Context, req *RegisterBody) (*Empty, error)

ReceivePing

@Description: grpc心跳
@receiver s
@param context.Context
@param *RegisterBody
@return *Empty
@return error

func (*RegisterCenter) RegisterEvent

func (s *RegisterCenter) RegisterEvent(name string, e InstanceEvent)

RegisterEvent

@Description: 注册事件
@receiver s
@param name
@param e

func (*RegisterCenter) RegisterServerBase

func (s *RegisterCenter) RegisterServerBase(ctx context.Context, req *RegisterBody) (*Empty, error)

RegisterServerBase

@Description: grpc服务注册
@receiver s
@param context.Context
@param *RegisterBody
@return *Empty
@return error

func (*RegisterCenter) RemoveMetadata

func (s *RegisterCenter) RemoveMetadata(serviceId, prefix, metadataKey string) error

RemoveMetadata

@Description: 移除指定元数据
@receiver s
@param serviceId
@param prefix
@param metadataKey
@return error

type ServerBase

type ServerBase struct {
	ServerId     string     //实例信息所在服务节点
	InstanceId   InstanceId //实例ID
	RegisterType int        //注册类型 0临时 1长期 2长期无心跳
	ServerType   string     //服务类型 GRPC / HTTP
	ServiceId    string     //业务ID
	RemoteAddr   string     //远程地址
	HealthEx     bool       //服务是否健康
	KeepPrefix   bool       //是否保留前缀
	LoadType     int        //0 轮训加载 1故障转移
	Private      bool       //是否私有
}

ServerBase @Description: 服务实例

func (*ServerBase) ToJson

func (s *ServerBase) ToJson() string

ToJson

@Description: 转成json字符串
@receiver s
@return string

type ServerRegisterServiceClient

type ServerRegisterServiceClient interface {
	//  保存用户设置
	RegisterServerBase(ctx context.Context, in *RegisterBody, opts ...grpc.CallOption) (*Empty, error)
	//  获取用户设置
	ReceivePing(ctx context.Context, in *RegisterBody, opts ...grpc.CallOption) (*Empty, error)
}

ServerRegisterServiceClient is the client API for ServerRegisterService service.

For semantics around ctx use and closing/ending streaming RPCs, please refer to https://pkg.go.dev/google.golang.org/grpc/?tab=doc#ClientConn.NewStream.

type ServerRegisterServiceServer

type ServerRegisterServiceServer interface {
	//  保存用户设置
	RegisterServerBase(context.Context, *RegisterBody) (*Empty, error)
	//  获取用户设置
	ReceivePing(context.Context, *RegisterBody) (*Empty, error)
	// contains filtered or unexported methods
}

ServerRegisterServiceServer is the server API for ServerRegisterService service. All implementations must embed UnimplementedServerRegisterServiceServer for forward compatibility

type UnimplementedServerRegisterServiceServer

type UnimplementedServerRegisterServiceServer struct {
}

UnimplementedServerRegisterServiceServer must be embedded to have forward compatible implementations.

func (UnimplementedServerRegisterServiceServer) ReceivePing

func (UnimplementedServerRegisterServiceServer) RegisterServerBase

type UnsafeServerRegisterServiceServer

type UnsafeServerRegisterServiceServer interface {
	// contains filtered or unexported methods
}

UnsafeServerRegisterServiceServer may be embedded to opt out of forward compatibility for this service. Use of this interface is not recommended, as added methods to ServerRegisterServiceServer will result in compilation errors.

type Version

type Version int64

服务实例集群版本号

func (Version) Finished

func (b Version) Finished()

Finished

@Description: 方法在消息将不再被广播时被调用,这可能是因为消息已被无效化或者因为达到了传输限制
当消息被发送完毕,或者由于某些原因(如无效化或传输限制)不再被广播时,会调用此方法。在该方法中,可以执行清理操作或释放资源
@receiver b

func (Version) Invalidates

func (b Version) Invalidates(other memberlist.Broadcast) bool

Invalidates

@Description: 方法用于检查当前广播消息是否使之前的广播消息无效。如果返回 true,则表示当前消息使前一个消息无效;如果返回 false,则表示当前消息不影响之前的消息
当将当前广播消息添加到广播队列时,会与先前的广播消息进行比较,以确定是否需要使先前的消息无效。在调用 Delegate 接口的 GetBroadcasts 方法时,用于检查是否需要替换之前的广播消息
@receiver b
@param other
@return bool

func (Version) Message

func (b Version) Message() []byte

Message

@Description: 方法用于获取当前广播消息的字节表示
在广播队列决定发送消息时,会调用此方法以获取要发送的消息内容。返回的字节切片将被传输到其他节点
@receiver b
@return []byte

Jump to

Keyboard shortcuts

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