cluster

package
v2.0.14 Latest Latest
Warning

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

Go to latest
Published: Oct 12, 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 added in v2.0.6

func GetNodeByTemplateServiceName(templateServiceName string) map[string]string

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

func GetNodeIdByTemplateService added in v2.0.6

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 added in v2.0.1

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

func (*Cluster) CanDiscoveryService added in v2.0.1

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 added in v2.0.1

func (cls *Cluster) GetEtcdDiscovery() *EtcdDiscovery

func (*Cluster) GetGlobalCfg

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

func (*Cluster) GetLocalNodeInfo

func (cls *Cluster) GetLocalNodeInfo() *NodeInfo

func (*Cluster) GetNatsUrl added in v2.0.1

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 added in v2.0.6

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 added in v2.0.1

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 added in v2.0.1

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 added in v2.0.1

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

func (*Cluster) NotifyAllService added in v2.0.1

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

func (*Cluster) ParseGlobalCfg added in v2.0.7

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 added in v2.0.1

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 added in v2.0.1

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

type DiscoveryService added in v2.0.1

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

type DiscoveryType added in v2.0.1

type DiscoveryType int

type EtcdDiscovery added in v2.0.1

type EtcdDiscovery struct {
	DialTimeoutMillisecond time.Duration
	TTLSecond              int64

	EtcdList []EtcdList
}

type EtcdDiscoveryService added in v2.0.1

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

func (*EtcdDiscoveryService) InitDiscovery added in v2.0.1

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

func (*EtcdDiscoveryService) OnEtcdDiscovery added in v2.0.1

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

func (*EtcdDiscoveryService) OnEventDelete added in v2.0.1

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

func (*EtcdDiscoveryService) OnEventGets added in v2.0.1

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

func (*EtcdDiscoveryService) OnEventPut added in v2.0.1

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

func (*EtcdDiscoveryService) OnInit added in v2.0.1

func (ed *EtcdDiscoveryService) OnInit() error

func (*EtcdDiscoveryService) OnNodeDisconnect added in v2.0.1

func (ed *EtcdDiscoveryService) OnNodeDisconnect(nodeId string)

func (*EtcdDiscoveryService) OnRelease added in v2.0.1

func (ed *EtcdDiscoveryService) OnRelease()

func (*EtcdDiscoveryService) OnRetire added in v2.0.1

func (ed *EtcdDiscoveryService) OnRetire()

func (*EtcdDiscoveryService) OnStart added in v2.0.1

func (ed *EtcdDiscoveryService) OnStart()

func (*EtcdDiscoveryService) RPC_ServiceRecord added in v2.0.1

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

type EtcdList added in v2.0.1

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

type FunDelNode

type FunDelNode func(nodeId string)

type FunSetNode added in v2.0.1

type FunSetNode func(nodeInfo *NodeInfo)

type IServiceDiscovery

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

type NatsConfig added in v2.0.1

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 //筛选发现的服务,如果不配置,不进行筛选

	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 added in v2.0.1

type OriginDiscovery struct {
	TTLSecond      int64
	MasterNodeList []NodeInfo
}

type OriginDiscoveryClient added in v2.0.1

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

func (*OriginDiscoveryClient) InitDiscovery added in v2.0.1

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

func (*OriginDiscoveryClient) OnInit added in v2.0.1

func (dc *OriginDiscoveryClient) OnInit() error

func (*OriginDiscoveryClient) OnNatsConnected added in v2.0.1

func (dc *OriginDiscoveryClient) OnNatsConnected()

func (*OriginDiscoveryClient) OnNatsDisconnect added in v2.0.1

func (dc *OriginDiscoveryClient) OnNatsDisconnect()

func (*OriginDiscoveryClient) OnNodeConnected added in v2.0.1

func (dc *OriginDiscoveryClient) OnNodeConnected(nodeId string)

func (*OriginDiscoveryClient) OnNodeDisconnect added in v2.0.1

func (dc *OriginDiscoveryClient) OnNodeDisconnect(nodeId string)

func (*OriginDiscoveryClient) OnRelease added in v2.0.1

func (dc *OriginDiscoveryClient) OnRelease()

func (*OriginDiscoveryClient) OnRetire added in v2.0.1

func (dc *OriginDiscoveryClient) OnRetire()

func (*OriginDiscoveryClient) OnStart added in v2.0.1

func (dc *OriginDiscoveryClient) OnStart()

func (*OriginDiscoveryClient) RPC_SubServiceDiscover added in v2.0.1

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

RPC_SubServiceDiscover 订阅发现的服务通知

type OriginDiscoveryMaster added in v2.0.1

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

func (*OriginDiscoveryMaster) OnInit added in v2.0.1

func (ds *OriginDiscoveryMaster) OnInit() error

func (*OriginDiscoveryMaster) OnNatsConnected added in v2.0.1

func (ds *OriginDiscoveryMaster) OnNatsConnected()

func (*OriginDiscoveryMaster) OnNatsDisconnect added in v2.0.1

func (ds *OriginDiscoveryMaster) OnNatsDisconnect()

func (*OriginDiscoveryMaster) OnNodeConnected added in v2.0.1

func (ds *OriginDiscoveryMaster) OnNodeConnected(nodeId string)

func (*OriginDiscoveryMaster) OnNodeDisconnect added in v2.0.1

func (ds *OriginDiscoveryMaster) OnNodeDisconnect(nodeId string)

func (*OriginDiscoveryMaster) OnStart added in v2.0.1

func (ds *OriginDiscoveryMaster) OnStart()

func (*OriginDiscoveryMaster) RPC_NodeRetire added in v2.0.1

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

func (*OriginDiscoveryMaster) RPC_Ping added in v2.0.1

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

func (*OriginDiscoveryMaster) RPC_RegServiceDiscover added in v2.0.1

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

收到注册过来的结点

func (*OriginDiscoveryMaster) RPC_UnRegServiceDiscover added in v2.0.1

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

func (*OriginDiscoveryMaster) RpcCastGo added in v2.0.1

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

type RpcMode added in v2.0.1

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