Skip to content

Commit

Permalink
copy from 1.5
Browse files Browse the repository at this point in the history
  • Loading branch information
ChangedenCZD committed Oct 18, 2021
1 parent c7ac72f commit 1184df2
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 16 deletions.
1 change: 1 addition & 0 deletions common/constant/key.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ const (
REGISTRY_TTL_KEY = "registry.ttl"
SIMPLIFIED_KEY = "simplified"
NAMESPACE_KEY = "namespace"
REGISTRY_GROUP_KEY = "registry.group"
)

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

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
11 changes: 2 additions & 9 deletions registry/nacos/listener.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,23 +185,16 @@ 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, defaultGroup)
}
return defaultGroup
}

func (nl *nacosListener) startListen() error {
if nl.namingClient == nil {
return perrors.New("nacos naming namingClient stopped")
}
serviceName := getSubscribeName(nl.listenUrl)
groupName := getSubscribeGroupName(nl.listenUrl)
groupName := nl.listenUrl.GetParam(constant.REGISTRY_GROUP_KEY, defaultGroup)
nl.subscribeParam = &vo.SubscribeParam{
ServiceName: serviceName,
GroupName: groupName,
SubscribeCallback: nl.Callback,
GroupName: groupName,
}
go func() {
_ = nl.namingClient.Client().Subscribe(nl.subscribeParam)
Expand Down
9 changes: 7 additions & 2 deletions registry/nacos/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ func (nr *nacosRegistry) Register(url *common.URL) error {
return nil
}

func createDeregisterParam(url *common.URL, serviceName string) vo.DeregisterInstanceParam {
func createDeregisterParam(url *common.URL, serviceName string, groupName string) vo.DeregisterInstanceParam {
if len(url.Ip) == 0 {
url.Ip = localIP
}
Expand All @@ -144,13 +144,15 @@ func createDeregisterParam(url *common.URL, serviceName string) vo.DeregisterIns
Ip: url.Ip,
Port: uint64(port),
ServiceName: serviceName,
GroupName: groupName,
Ephemeral: true,
}
}

func (nr *nacosRegistry) DeRegister(url *common.URL) error {
serviceName := getServiceName(url)
param := createDeregisterParam(url, serviceName)
groupName := nr.URL.GetParam(constant.GROUP_KEY, defaultGroup)
param := createDeregisterParam(url, serviceName, groupName)
isDeRegistry, err := nr.namingClient.Client().DeregisterInstance(param)
if err != nil {
return err
Expand Down Expand Up @@ -185,6 +187,9 @@ func (nr *nacosRegistry) Subscribe(url *common.URL, notifyListener registry.Noti
return perrors.New("nacosRegistry is not available.")
}

groupName := nr.GetParam(constant.GROUP_KEY, defaultGroup)
url.SetParam(constant.REGISTRY_GROUP_KEY, groupName) // update to registry.group

listener, err := nr.subscribe(url)
if err != nil {
if !nr.IsAvailable() {
Expand Down
2 changes: 2 additions & 0 deletions registry/nacos/service_discovery.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ func (n *nacosServiceDiscovery) GetInstances(serviceName string) []registry.Serv
Enable: ins.Enable,
Healthy: ins.Healthy,
Metadata: metadata,
GroupName: n.group,
})
}
return res
Expand Down Expand Up @@ -269,6 +270,7 @@ func (n *nacosServiceDiscovery) AddListener(listener registry.ServiceInstancesCh
Enable: service.Enable,
Healthy: true,
Metadata: metadata,
GroupName: n.group,
})
}

Expand Down
1 change: 1 addition & 0 deletions registry/service_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ type DefaultServiceInstance struct {
Metadata map[string]string
ServiceMetadata *common.MetadataInfo
Address string
GroupName string
}

// GetID will return this instance's id. It should be unique.
Expand Down

0 comments on commit 1184df2

Please sign in to comment.