feat 初始化
This commit is contained in:
@@ -10,23 +10,37 @@ const (
|
||||
)
|
||||
|
||||
var (
|
||||
KeyDiscover = "xh-discover"
|
||||
KeyDiscover = "/discover"
|
||||
KeyDiscoverService = KeyDiscover + "/service"
|
||||
KeyDiscoverInstance = KeyDiscover + "/instance"
|
||||
)
|
||||
|
||||
var (
|
||||
KeyDiscoverServiceNameGateway = "gateway" // 网关服
|
||||
KeyDiscoverServiceNameScene = "scene" // 场景服
|
||||
KeyDiscoverServiceNameUser = "user" // 用户中心
|
||||
KeyDiscoverServiceNameQgdzs = "qgdzs" // 奇怪的知识-服务端
|
||||
KeyDiscoverServiceNameGateway = "01-gateway" // 网关服
|
||||
KeyDiscoverServiceNameScene = "02-scene" // 场景服
|
||||
KeyDiscoverServiceNameUser = "03-user" // 用户中心
|
||||
KeyDiscoverServiceNameThirdParty = "04-third-party" // 三方登录服
|
||||
KeyDiscoverServiceNamePost = "05-post" // 推送服
|
||||
KeyDiscoverServiceNameAnnouncement = "06-announcement" // 公告服
|
||||
KeyDiscoverServiceNameCourt = "07-court" // 球场服
|
||||
KeyDiscoverServiceNameAdmin = "08-admin" // 后台服
|
||||
KeyDiscoverServiceNameCourtPhysical = "09-court-physical" // 线下球场服
|
||||
KeyDiscoverServiceNameTimer = "10-timer" // 定时任务服(只起一个)
|
||||
KeyDiscoverServiceNameQgdzs = "11-qgdzs" // 奇怪的知识
|
||||
)
|
||||
|
||||
var (
|
||||
KeyDiscoverGateway = KeyDiscoverService + "/" + KeyDiscoverServiceNameGateway // 网关服
|
||||
KeyDiscoverScene = KeyDiscoverService + "/" + KeyDiscoverServiceNameScene // 场景服
|
||||
KeyDiscoverUser = KeyDiscoverService + "/" + KeyDiscoverServiceNameUser // 用户中心
|
||||
KeyDiscoverQgdzs = KeyDiscoverService + "/" + KeyDiscoverServiceNameQgdzs // 奇怪的知识-服务端
|
||||
KeyDiscoverGateway = KeyDiscoverService + "/" + KeyDiscoverServiceNameGateway // 网关服
|
||||
KeyDiscoverScene = KeyDiscoverService + "/" + KeyDiscoverServiceNameScene // 场景服
|
||||
KeyDiscoverUser = KeyDiscoverService + "/" + KeyDiscoverServiceNameUser // 用户中心
|
||||
KeyDiscoverThirdParty = KeyDiscoverService + "/" + KeyDiscoverServiceNameThirdParty // 三方登录服
|
||||
KeyDiscoverPost = KeyDiscoverService + "/" + KeyDiscoverServiceNamePost // 推送服
|
||||
KeyDiscoverAnnouncement = KeyDiscoverService + "/" + KeyDiscoverServiceNameAnnouncement // 公告服
|
||||
KeyDiscoverCourt = KeyDiscoverService + "/" + KeyDiscoverServiceNameCourt // 球场服
|
||||
KeyDiscoverAdmin = KeyDiscoverService + "/" + KeyDiscoverServiceNameAdmin // 后台服
|
||||
KeyDiscoverCourtPhysical = KeyDiscoverService + "/" + KeyDiscoverServiceNameCourtPhysical // 线下球场服
|
||||
KeyDiscoverTimer = KeyDiscoverService + "/" + KeyDiscoverServiceNameTimer // 定时任务服(只起一个)
|
||||
KeyDiscoverQgdzs = KeyDiscoverService + "/" + KeyDiscoverServiceNameQgdzs // 奇怪的知识
|
||||
)
|
||||
|
||||
// ServiceProvider 服务提供者
|
||||
|
||||
@@ -83,20 +83,20 @@ func Listen(ready *sync.WaitGroup) {
|
||||
// 服务发生变化
|
||||
func onServerChange(t mvccpb.Event_EventType, key, value string) {
|
||||
split := strings.Split(key, "/")
|
||||
if len(split) != 4 {
|
||||
if len(split) != 5 {
|
||||
return
|
||||
}
|
||||
switch t {
|
||||
case clientv3.EventTypePut:
|
||||
onCBByType(common.ListenerTypeNewServer, &common.ServiceProvider{
|
||||
Target: common.KeyDiscoverService + "/" + split[2],
|
||||
SID: utils.StringToInt64(split[3]),
|
||||
Target: common.KeyDiscoverService + "/" + split[3],
|
||||
SID: utils.StringToInt64(split[4]),
|
||||
Addr: value,
|
||||
})
|
||||
case clientv3.EventTypeDelete:
|
||||
onCBByType(common.ListenerTypeCloseServer, &common.ServiceProvider{
|
||||
Target: common.KeyDiscoverService + "/" + split[2],
|
||||
SID: utils.StringToInt64(split[3]),
|
||||
Target: common.KeyDiscoverService + "/" + split[3],
|
||||
SID: utils.StringToInt64(split[4]),
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -104,21 +104,21 @@ func onServerChange(t mvccpb.Event_EventType, key, value string) {
|
||||
// 副本发生变化
|
||||
func onInstanceChange(t mvccpb.Event_EventType, key, value string, preKv *mvccpb.KeyValue) {
|
||||
split := strings.Split(key, "/")
|
||||
if len(split) != 4 {
|
||||
if len(split) != 5 {
|
||||
return
|
||||
}
|
||||
instanceID, _ := strconv.Atoi(split[2])
|
||||
instanceID, _ := strconv.Atoi(split[3])
|
||||
switch t {
|
||||
case clientv3.EventTypePut:
|
||||
onCBByType(common.ListenerTypeNewInstance, &common.InstanceProvider{
|
||||
InstanceID: instanceID,
|
||||
UniqueNo: utils.StringToInt64(split[3]),
|
||||
UniqueNo: utils.StringToInt64(split[4]),
|
||||
SID: utils.StringToInt64(value),
|
||||
})
|
||||
case clientv3.EventTypeDelete:
|
||||
onCBByType(common.ListenerTypeCloseInstance, &common.InstanceProvider{
|
||||
InstanceID: instanceID,
|
||||
UniqueNo: utils.StringToInt64(split[3]),
|
||||
UniqueNo: utils.StringToInt64(split[4]),
|
||||
SID: utils.StringToInt64(string(preKv.Value)),
|
||||
})
|
||||
}
|
||||
|
||||
@@ -42,6 +42,15 @@ func FindServerAll(target string) map[int64]*grpc.ClientConn {
|
||||
return make(map[int64]*grpc.ClientConn)
|
||||
}
|
||||
|
||||
func FindServerAllSid(target string) []int64 {
|
||||
serverMU.RLock()
|
||||
defer serverMU.RUnlock()
|
||||
if v, ok := conn[target]; ok {
|
||||
return v.LoadAllSid()
|
||||
}
|
||||
return make([]int64, 0)
|
||||
}
|
||||
|
||||
// RegisterGrpcServer 注册服务提供者
|
||||
func RegisterGrpcServer(target string, sid int64, addr string, ttl int64) error {
|
||||
serverMU.Lock()
|
||||
|
||||
Reference in New Issue
Block a user