Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

V2.0.2 namingClient.Subscribe 订阅服务状态, 当服务变化推送过来,因为集群为"",无法取到缓存回调方法 #474

Closed
chuckie-cheng opened this issue Jun 13, 2022 · 5 comments
Labels
2.0.0 bug Something isn't working

Comments

@chuckie-cheng
Copy link

// Subscribe key = serviceName+groupName+cluster
// Note: We call add multiple SubscribeCallback with the same key.
err := namingClient.Subscribe(vo.SubscribeParam{
ServiceName: "demo.go",
GroupName: "group-a", // default value is DEFAULT_GROUP
Clusters: []string{"DEFAULT"}, // default value is DEFAULT
SubscribeCallback: func(services []model.SubscribeService, err error) {
log.Printf("\n\n callback return services:%s \n\n", utils.ToJsonString(services))
},
})

问题:源码中
funcs, ok := ed.callbackFuncMap.Get(cacheKey)
获取不到回调方法 因为 cacheKey组成的cluster字段为"",订阅初始化是存入的cacheKey中cluster为"DEFAULT"

func (ed *SubscribeCallback) ServiceChanged(cacheKey string, service *model.Service) {
funcs, ok := ed.callbackFuncMap.Get(cacheKey)
if ok {
for _, funcItem := range funcs.([]*func(services []model.Instance, err error)) {
if len(service.Hosts) == 0 {
(*funcItem)(service.Hosts, errors.New("[client.Subscribe] subscribe failed,hosts is empty"))
continue
}
(*funcItem)(service.Hosts, nil)
}
}
}

另外cluster为""的好像是
common/remote/rpc/server_request_handler.go
中RequestReply方法,请求返回的数据中 clusters为""

@binbin0325 binbin0325 added bug Something isn't working 2.0.0 labels Jun 13, 2022
@chuckie-cheng
Copy link
Author

接受服务信息日志打印:service key:%s was updated to:%s

service key: TEST-CHENG-LEIGOTES
"cacheMillis": 10000
"hosts": I
G-LEI was updated to:
"instanceld":..
"1p": "10.113.87.60",
"port": 1000000
"weight": 1,
"healthy": true,
"enabled" : true,
"ephemeral": true,
"clusterName": "DEFAULT"
"serviceName": "TEST-CHENG-LEIG@TEST-CHENG-LEI"
"metadata": 0,
"instancelleartBeatInterval":5001
"1pDeleteTimeout": 30000,
"instanceHeartBeatT1meOut": 15000
J.
E
"instanceld":
"1p": "10.113.87.60",
"port": 0,
"weight": 1,
"healthy": true,
"enabled": trad
"ephemeral": true,
"clusterName" : "DEFAULT",
"serviceName":
"TEST-CHENG-LEIC@TEST-CHENG-LEI,
"metadata": (
"name":
"chuckie",
"value": "test-
-1111"
J.
"instanceHeartBeatInterval":5000,
"ipDeleteTimeout": 30000,
"instanceHeartBeatTime0ut": 15000
5.
1,
"checksum":
"lastRefTime": 1655172700425,
"clusters": ''",
"name": "TEST-CHENG-LEI",
"groupName" : "TEST-CHENG
"valid": true,
"allIpg"; false,
"reachProtectionThreshold" : false
}

@binbin0325
Copy link
Member

没有复现,可以用最新版本再试下

@xushuhui
Copy link
Contributor

v2.2.5 ,如果"clusters" : "DEFAULT“ 在调用Subscribe 复现 bug,但是 "clusters" : "”没有复现

@tureo
Copy link

tureo commented Jun 12, 2024

v2.2.5 ,如果"clusters" : "DEFAULT“ 在调用Subscribe 复现 bug,但是 "clusters" : "”没有复现

有解决方式吗?
我使用nacos sever v2.0.2和nacos go sdk v2.2.6也存在这个问题,vo.SubscribeParam配置Clusters: []string{"cluster-a"}后就有问题,示例中没有配置clusters就没问题

SubscribeCallback: func(services []model.Instance, err error) {

@youzhixiaomutou
Copy link

#761

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
2.0.0 bug Something isn't working
Projects
None yet
Development

No branches or pull requests

5 participants