in pkg/adapter/dubboregistry/registry/nacos/registry.go [62:104]
func newNacosRegistry(regConfig model.Registry, adapterListener common.RegistryEventListener) (registry.Registry, error) {
addrs, err := stringutil.GetIPAndPort(regConfig.Address)
if err != nil {
return nil, err
}
scs := make([]nacosConstant.ServerConfig, 0)
for _, addr := range addrs {
scs = append(scs, nacosConstant.ServerConfig{
IpAddr: addr.IP.String(),
Port: uint64(addr.Port),
})
}
ccs := nacosConstant.NewClientConfig(
nacosConstant.WithNamespaceId(regConfig.Namespace),
nacosConstant.WithUsername(regConfig.Username),
nacosConstant.WithPassword(regConfig.Password),
nacosConstant.WithNotLoadCacheAtStart(true),
nacosConstant.WithUpdateCacheWhenEmpty(true))
client, err := clients.NewNamingClient(vo.NacosClientParam{
ServerConfigs: scs,
ClientConfig: ccs,
})
if err != nil {
return nil, err
}
nacosRegistry := &NacosRegistry{
client: client,
nacosListeners: make(map[registry.RegisteredType]registry.Listener),
}
nacosRegistry.BaseRegistry = baseRegistry.NewBaseRegistry(nacosRegistry, adapterListener, registry.RegisterTypeFromName(regConfig.RegistryType))
switch nacosRegistry.RegisteredType {
case registry.RegisteredTypeInterface:
nacosRegistry.nacosListeners[nacosRegistry.RegisteredType] = newNacosIntfListener(client, nacosRegistry, ®Config, adapterListener)
case registry.RegisteredTypeApplication:
nacosRegistry.nacosListeners[nacosRegistry.RegisteredType] = newNacosAppListener(client, nacosRegistry, ®Config, adapterListener)
default:
return nil, errors.Errorf("Unsupported registry type: %s", regConfig.RegistryType)
}
return nacosRegistry, nil
}