1
0
mirror of https://github.com/go-kratos/kratos.git synced 2025-03-17 21:07:54 +02:00

nacos stop cannot cancel subscription (#3173)

This commit is contained in:
Liang Chen 2024-03-20 09:51:35 +08:00 committed by GitHub
parent 1ab258e53f
commit cd9857fc59
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -14,14 +14,15 @@ import (
var _ registry.Watcher = (*watcher)(nil)
type watcher struct {
serviceName string
clusters []string
groupName string
ctx context.Context
cancel context.CancelFunc
watchChan chan struct{}
cli naming_client.INamingClient
kind string
serviceName string
clusters []string
groupName string
ctx context.Context
cancel context.CancelFunc
watchChan chan struct{}
cli naming_client.INamingClient
kind string
subscribeParam *vo.SubscribeParam
}
func newWatcher(ctx context.Context, cli naming_client.INamingClient, serviceName, groupName, kind string, clusters []string) (*watcher, error) {
@ -35,14 +36,15 @@ func newWatcher(ctx context.Context, cli naming_client.INamingClient, serviceNam
}
w.ctx, w.cancel = context.WithCancel(ctx)
e := w.cli.Subscribe(&vo.SubscribeParam{
w.subscribeParam = &vo.SubscribeParam{
ServiceName: serviceName,
Clusters: clusters,
GroupName: groupName,
SubscribeCallback: func(services []model.SubscribeService, err error) {
w.watchChan <- struct{}{}
},
})
}
e := w.cli.Subscribe(w.subscribeParam)
return w, e
}
@ -78,10 +80,7 @@ func (w *watcher) Next() ([]*registry.ServiceInstance, error) {
}
func (w *watcher) Stop() error {
err := w.cli.Unsubscribe(w.subscribeParam)
w.cancel()
return w.cli.Unsubscribe(&vo.SubscribeParam{
ServiceName: w.serviceName,
GroupName: w.groupName,
Clusters: w.clusters,
})
return err
}