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

Ftr: Support Custom Registry GroupName on Nacos #1353

5 changes: 5 additions & 0 deletions registry/directory/directory.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,11 @@ func NewRegistryDirectory(url *common.URL, registry registry.Registry) (cluster.

dir.consumerConfigurationListener = newConsumerConfigurationListener(dir)

// exchange data
subUrl := url.Clone()
subUrl.SubURL = nil
url.SubURL.SubURL = subUrl

go dir.subscribe(url.SubURL)
return dir, nil
}
Expand Down
14 changes: 13 additions & 1 deletion registry/nacos/listener.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,12 +183,24 @@ func getSubscribeName(url *common.URL) string {
return buffer.String()
}

func getSubscribeGroupName(url *common.URL) string {
if url.SubURL != nil {
return url.SubURL.GetParam(constant.GROUP_KEY, "")
}
return ""
}

func (nl *nacosListener) startListen() error {
if nl.namingClient == nil {
return perrors.New("nacos naming namingClient stopped")
}
serviceName := getSubscribeName(nl.listenUrl)
nl.subscribeParam = &vo.SubscribeParam{ServiceName: serviceName, SubscribeCallback: nl.Callback}
groupName := getSubscribeGroupName(nl.listenUrl)
nl.subscribeParam = &vo.SubscribeParam{
ServiceName: serviceName,
GroupName: groupName,
SubscribeCallback: nl.Callback,
}
go func() {
_ = nl.namingClient.Client().Subscribe(nl.subscribeParam)
}()
Expand Down
6 changes: 4 additions & 2 deletions registry/nacos/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ func appendParam(target *bytes.Buffer, url *common.URL, key string) {
}
}

func createRegisterParam(url *common.URL, serviceName string) vo.RegisterInstanceParam {
func createRegisterParam(url *common.URL, serviceName string, groupName string) vo.RegisterInstanceParam {
category := getCategory(url)
params := make(map[string]string)

Expand Down Expand Up @@ -109,14 +109,16 @@ func createRegisterParam(url *common.URL, serviceName string) vo.RegisterInstanc
Healthy: true,
Ephemeral: true,
ServiceName: serviceName,
GroupName: groupName,
}
return instance
}

// Register will register the service @url to its nacos registry center
func (nr *nacosRegistry) Register(url *common.URL) error {
serviceName := getServiceName(url)
param := createRegisterParam(url, serviceName)
groupName := nr.URL.GetParam(constant.GROUP_KEY, "")
ChangedenCZD marked this conversation as resolved.
Show resolved Hide resolved
param := createRegisterParam(url, serviceName, groupName)
isRegistry, err := nr.namingClient.Client().RegisterInstance(param)
if err != nil {
return err
Expand Down