cluster

package
v1.0.3 Latest Latest
Warning

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

Go to latest
Published: Nov 20, 2024 License: Apache-2.0 Imports: 24 Imported by: 0

Documentation

Index

Constants

View Source
const (
	InvalidType = 0
	OriginType  = 1
	EtcdType    = 2
)
View Source
const MinTTL = 3
View Source
const NodeRetireRpcMethod = OriginDiscoveryMasterName + ".RPC_NodeRetire"
View Source
const OriginDiscoveryClientName = "DiscoveryClient"
View Source
const OriginDiscoveryMasterName = "DiscoveryMaster"
View Source
const RegServiceDiscover = OriginDiscoveryMasterName + ".RPC_RegServiceDiscover"
View Source
const RpcPingMethod = OriginDiscoveryMasterName + ".RPC_Ping"
View Source
const SubServiceDiscover = OriginDiscoveryClientName + ".RPC_SubServiceDiscover"
View Source
const UnRegServiceDiscover = OriginDiscoveryMasterName + ".RPC_UnRegServiceDiscover"

Variables

This section is empty.

Functions

func GetNodeByServiceName

func GetNodeByServiceName(serviceName string) map[string]struct{}

func GetNodeByTemplateServiceName

func GetNodeByTemplateServiceName(templateServiceName string) map[string]string

GetNodeByTemplateServiceName 通过模板服务名获取服务名,返回 map[serviceName真实服务名]NodeId

func GetNodeIdByTemplateService

func GetNodeIdByTemplateService(templateServiceName string, rpcClientList []*rpc.Client, filterRetire bool) (error, []*rpc.Client)

func GetRpcClient

func GetRpcClient(nodeId string, serviceMethod string, filterRetire bool, clientList []*rpc.Client) (error, []*rpc.Client)

func GetRpcServer

func GetRpcServer() rpc.IServer

func HasService

func HasService(nodeId string, serviceName string) bool

func SetConfigDir

func SetConfigDir(cfgDir string)

func SetServiceDiscovery

func SetServiceDiscovery(serviceDiscovery IServiceDiscovery)

Types

type Cluster

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

func GetCluster

func GetCluster() *Cluster

func (*Cluster) AddDiscoveryService

func (cls *Cluster) AddDiscoveryService(serviceName string, bPublicService bool)

func (*Cluster) CanDiscoveryService

func (cls *Cluster) CanDiscoveryService(fromMasterNodeId string, serviceName string) bool

func (*Cluster) DelNode

func (cls *Cluster) DelNode(nodeId string)

func (*Cluster) DiscardNode

func (cls *Cluster) DiscardNode(nodeId string)

func (*Cluster) FindRpcHandler

func (cls *Cluster) FindRpcHandler(serviceName string) rpc.IRpcHandler

func (*Cluster) GetEtcdDiscovery

func (cls *Cluster) GetEtcdDiscovery() *EtcdDiscovery

func (*Cluster) GetGlobalCfg

func (cls *Cluster) GetGlobalCfg() interface{}

func (*Cluster) GetLocalNodeInfo

func (cls *Cluster) GetLocalNodeInfo() *NodeInfo

func (*Cluster) GetNatsUrl

func (cls *Cluster) GetNatsUrl() string

func (*Cluster) GetNodeIdByService

func (cls *Cluster) GetNodeIdByService(serviceName string, rpcClientList []*rpc.Client, filterRetire bool) (error, []*rpc.Client)

func (*Cluster) GetNodeIdByTemplateService

func (cls *Cluster) GetNodeIdByTemplateService(templateServiceName string, rpcClientList []*rpc.Client, filterRetire bool) (error, []*rpc.Client)

func (*Cluster) GetNodeInfo

func (cls *Cluster) GetNodeInfo(nodeId string) (NodeInfo, bool)

func (*Cluster) GetOriginDiscovery

func (cls *Cluster) GetOriginDiscovery() *OriginDiscovery

func (*Cluster) GetRpcClient

func (cls *Cluster) GetRpcClient(nodeId string) (*rpc.Client, bool)

func (*Cluster) GetServiceCfg

func (cls *Cluster) GetServiceCfg(serviceName string) interface{}

func (*Cluster) Init

func (cls *Cluster) Init(localNodeId string, setupServiceFun SetupServiceFun) error

func (*Cluster) InitCfg

func (cls *Cluster) InitCfg(localNodeId string) error

func (*Cluster) IsConfigService

func (cls *Cluster) IsConfigService(serviceName string) bool

func (*Cluster) IsNatsMode

func (cls *Cluster) IsNatsMode() bool

func (*Cluster) IsNodeConnected

func (cls *Cluster) IsNodeConnected(nodeId string) bool

func (*Cluster) IsNodeRetire

func (cls *Cluster) IsNodeRetire(nodeId string) bool

func (*Cluster) IsOriginMasterDiscoveryNode

func (cls *Cluster) IsOriginMasterDiscoveryNode(nodeId string) bool

func (*Cluster) NotifyAllService

func (cls *Cluster) NotifyAllService(event event.IEvent)

func (*Cluster) ParseGlobalCfg

func (cls *Cluster) ParseGlobalCfg(cfg interface{}) error

func (*Cluster) ReadClusterConfig

func (cls *Cluster) ReadClusterConfig(filepath string) (*NodeInfoList, error)

func (*Cluster) RegRpcEvent

func (cls *Cluster) RegRpcEvent(serviceName string)

func (*Cluster) SetRpcMode

func (cls *Cluster) SetRpcMode(cfgRpcMode *RpcMode, rpcMode *RpcMode) error

func (*Cluster) Start

func (cls *Cluster) Start() error

func (*Cluster) Stop

func (cls *Cluster) Stop()

func (*Cluster) TriggerDiscoveryEvent

func (cls *Cluster) TriggerDiscoveryEvent(bDiscovery bool, nodeId string, serviceName []string)

func (*Cluster) UnRegRpcEvent

func (cls *Cluster) UnRegRpcEvent(serviceName string)

type ConfigDiscovery

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

func (*ConfigDiscovery) InitDiscovery

func (discovery *ConfigDiscovery) InitDiscovery(localNodeId string, funDelNode FunDelNode, funSetNode FunSetNode) error

type DiscoveryInfo

type DiscoveryInfo struct {
	Etcd   *EtcdDiscovery   //etcd
	Origin *OriginDiscovery //origin
	// contains filtered or unexported fields
}

type DiscoveryService

type DiscoveryService struct {
	MasterNodeId string   //要筛选的主结点Id,如果不配置或者配置成0,表示针对所有的主结点
	NetworkName  string   //如果是etcd,指定要筛选的网络名中的服务,不配置,表示所有的网络
	ServiceList  []string //只发现的服务列表
}

type DiscoveryType

type DiscoveryType int

type EtcdDiscovery

type EtcdDiscovery struct {
	DialTimeoutMillisecond time.Duration
	TTLSecond              int64

	EtcdList []EtcdList
}

type EtcdDiscoveryService

type EtcdDiscoveryService struct {
	service.Service
	// contains filtered or unexported fields
}

func (*EtcdDiscoveryService) InitDiscovery

func (ed *EtcdDiscoveryService) InitDiscovery(localNodeId string, funDelNode FunDelNode, funSetNode FunSetNode) error

func (*EtcdDiscoveryService) OnEtcdDiscovery

func (ed *EtcdDiscoveryService) OnEtcdDiscovery(ev event.IEvent)

func (*EtcdDiscoveryService) OnEventDelete

func (ed *EtcdDiscoveryService) OnEventDelete(watchKey string, Kv *mvccpb.KeyValue)

func (*EtcdDiscoveryService) OnEventGets

func (ed *EtcdDiscoveryService) OnEventGets(watchKey string, Kvs []*mvccpb.KeyValue)

func (*EtcdDiscoveryService) OnEventPut

func (ed *EtcdDiscoveryService) OnEventPut(watchKey string, Kv *mvccpb.KeyValue)

func (*EtcdDiscoveryService) OnInit

func (ed *EtcdDiscoveryService) OnInit() error

func (*EtcdDiscoveryService) OnNodeDisconnect

func (ed *EtcdDiscoveryService) OnNodeDisconnect(nodeId string)

func (*EtcdDiscoveryService) OnRelease

func (ed *EtcdDiscoveryService) OnRelease()

func (*EtcdDiscoveryService) OnRetire

func (ed *EtcdDiscoveryService) OnRetire()

func (*EtcdDiscoveryService) OnStart

func (ed *EtcdDiscoveryService) OnStart()

func (*EtcdDiscoveryService) RPC_ServiceRecord

func (ed *EtcdDiscoveryService) RPC_ServiceRecord(etcdServiceRecord *service.EtcdServiceRecordEvent, empty *service.Empty) error

type EtcdList

type EtcdList struct {
	NetworkName []string
	Endpoints   []string
}

type FunDelNode

type FunDelNode func(nodeId string)

type FunSetNode

type FunSetNode func(nodeInfo *NodeInfo)

type IServiceDiscovery

type IServiceDiscovery interface {
	InitDiscovery(localNodeId string, funDelNode FunDelNode, funSetNodeInfo FunSetNode) error
}

type LogConfig

type LogConfig struct {
	Encoder    string //日志编码方式 console|json 默认console
	Level      string //日志级别 debug|info|warning|error|fatal 默认console
	OutputType string //日志输出方式 console|file|all 默认all (console:只输出到控制台,file:只输出到文件,all:即输出到控制台也输出到文件)
	Path       string //文件日志输出的目录 默认 ./log
	FlieSize   int    //文件最大日志大小(Mb级别) 默认 100
}

type NatsConfig

type NatsConfig struct {
	NatsUrl     string
	NoRandomize bool
}

type NodeInfo

type NodeInfo struct {
	NodeId            string
	Private           bool
	ListenAddr        string
	MaxRpcParamLen    uint32             //最大Rpc参数长度
	CompressBytesLen  int                //超过字节进行压缩的长度
	ServiceList       []string           //所有的有序服务列表
	PublicServiceList []string           //对外公开的服务列表
	DiscoveryService  []DiscoveryService //筛选发现的服务,如果不配置,不进行筛选
	LogCfg            LogConfig          //节点日志相关配置

	Retire bool

	NetworkName string
	// contains filtered or unexported fields
}

type NodeInfoList

type NodeInfoList struct {
	RpcMode   RpcMode
	Discovery DiscoveryInfo
	NodeList  []NodeInfo
}

type NodeRpcInfo

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

type NodeStatus

type NodeStatus int
const (
	Normal  NodeStatus = 0 //正常
	Discard NodeStatus = 1 //丢弃
)

type OperType

type OperType int

type OriginDiscovery

type OriginDiscovery struct {
	TTLSecond      int64
	MasterNodeList []NodeInfo
}

type OriginDiscoveryClient

type OriginDiscoveryClient struct {
	service.Service
	// contains filtered or unexported fields
}

func (*OriginDiscoveryClient) InitDiscovery

func (dc *OriginDiscoveryClient) InitDiscovery(localNodeId string, funDelNode FunDelNode, funSetNode FunSetNode) error

func (*OriginDiscoveryClient) OnInit

func (dc *OriginDiscoveryClient) OnInit() error

func (*OriginDiscoveryClient) OnNatsConnected

func (dc *OriginDiscoveryClient) OnNatsConnected()

func (*OriginDiscoveryClient) OnNatsDisconnect

func (dc *OriginDiscoveryClient) OnNatsDisconnect()

func (*OriginDiscoveryClient) OnNodeConnected

func (dc *OriginDiscoveryClient) OnNodeConnected(nodeId string)

func (*OriginDiscoveryClient) OnNodeDisconnect

func (dc *OriginDiscoveryClient) OnNodeDisconnect(nodeId string)

func (*OriginDiscoveryClient) OnRelease

func (dc *OriginDiscoveryClient) OnRelease()

func (*OriginDiscoveryClient) OnRetire

func (dc *OriginDiscoveryClient) OnRetire()

func (*OriginDiscoveryClient) OnStart

func (dc *OriginDiscoveryClient) OnStart()

func (*OriginDiscoveryClient) RPC_SubServiceDiscover

func (dc *OriginDiscoveryClient) RPC_SubServiceDiscover(req *rpc.SubscribeDiscoverNotify) error

RPC_SubServiceDiscover 订阅发现的服务通知

type OriginDiscoveryMaster

type OriginDiscoveryMaster struct {
	service.Service
	// contains filtered or unexported fields
}

func (*OriginDiscoveryMaster) OnInit

func (ds *OriginDiscoveryMaster) OnInit() error

func (*OriginDiscoveryMaster) OnNatsConnected

func (ds *OriginDiscoveryMaster) OnNatsConnected()

func (*OriginDiscoveryMaster) OnNatsDisconnect

func (ds *OriginDiscoveryMaster) OnNatsDisconnect()

func (*OriginDiscoveryMaster) OnNodeConnected

func (ds *OriginDiscoveryMaster) OnNodeConnected(nodeId string)

func (*OriginDiscoveryMaster) OnNodeDisconnect

func (ds *OriginDiscoveryMaster) OnNodeDisconnect(nodeId string)

func (*OriginDiscoveryMaster) OnStart

func (ds *OriginDiscoveryMaster) OnStart()

func (*OriginDiscoveryMaster) RPC_NodeRetire

func (ds *OriginDiscoveryMaster) RPC_NodeRetire(req *rpc.NodeRetireReq, _ *rpc.Empty) error

func (*OriginDiscoveryMaster) RPC_Ping

func (ds *OriginDiscoveryMaster) RPC_Ping(req *rpc.Ping, res *rpc.Pong) error

func (*OriginDiscoveryMaster) RPC_RegServiceDiscover

func (ds *OriginDiscoveryMaster) RPC_RegServiceDiscover(req *rpc.RegServiceDiscoverReq, res *rpc.SubscribeDiscoverNotify) error

收到注册过来的结点

func (*OriginDiscoveryMaster) RPC_UnRegServiceDiscover

func (ds *OriginDiscoveryMaster) RPC_UnRegServiceDiscover(req *rpc.UnRegServiceDiscoverReq, _ *rpc.Empty) error

func (*OriginDiscoveryMaster) RpcCastGo

func (ds *OriginDiscoveryMaster) RpcCastGo(serviceMethod string, args interface{})

type RpcMode

type RpcMode struct {
	Typ  string `json:"Type"`
	Nats NatsConfig
}

type SetupServiceFun

type SetupServiceFun func(s ...service.IService)

Jump to

Keyboard shortcuts

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