Skip to content

Commit 761f0e0

Browse files
authored
Fix: Same address cannot distinguish different registry center (#2784)
* fix: Same address cannot distinguish different registry center * fix: Same address cannot distinguish different registry center * registry.namespace is set to a constant,
1 parent 2b15cb0 commit 761f0e0

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

registry/protocol/protocol.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,14 +80,20 @@ func newRegistryProtocol() *registryProtocol {
8080

8181
func (proto *registryProtocol) getRegistry(registryUrl *common.URL) registry.Registry {
8282
var err error
83-
reg, loaded := proto.registries.Load(registryUrl.PrimitiveURL)
83+
84+
namespace := registryUrl.GetParam(constant.RegistryNamespaceKey, "")
85+
cacheKey := registryUrl.PrimitiveURL
86+
if namespace != "" {
87+
cacheKey = cacheKey + "?" + constant.NacosNamespaceID + "=" + namespace
88+
}
89+
reg, loaded := proto.registries.Load(cacheKey)
8490
if !loaded {
8591
reg, err = extension.GetRegistry(registryUrl.Protocol, registryUrl)
8692
if err != nil {
8793
logger.Errorf("Registry can not connect success, program is going to panic.Error message is %s", err.Error())
8894
panic(err)
8995
}
90-
proto.registries.Store(registryUrl.PrimitiveURL, reg)
96+
proto.registries.Store(cacheKey, reg)
9197
}
9298
return reg.(registry.Registry)
9399
}

remoting/nacos/builder.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,5 +122,9 @@ func NewNacosClientByURL(url *common.URL) (*nacosClient.NacosNamingClient, error
122122
return nil, perrors.New("nacos client name must set")
123123
}
124124
logger.Infof("[Nacos Client] New nacos client with config = %+v", scs)
125+
namespaceID := url.GetParam(constant.NacosNamespaceID, "")
126+
if len(namespaceID) > 0 {
127+
clientName += namespaceID
128+
}
125129
return nacosClient.NewNacosNamingClient(clientName, true, scs, cc)
126130
}

0 commit comments

Comments
 (0)