@Override
    public List<ProviderGroup> subscribe(final ConsumerConfig config) {
        String appName = config.getAppName();
        if (!registryConfig.isSubscribe()) {
            // registry ignored
            if (LOGGER.isInfoEnabled(appName)) {
                LOGGER.infoWithApp(appName, LogCodes.getLog(LogCodes.INFO_REGISTRY_IGNORE));
            }
            return null;
        }

        if (config.isSubscribe()) {
            String serviceName = NacosRegistryHelper.buildServiceName(config, config.getProtocol());

            if (LOGGER.isInfoEnabled()) {
                LOGGER.infoWithApp(appName, LogCodes.getLog(LogCodes.INFO_ROUTE_REGISTRY_SUB, serviceName));
            }

            try {
                ProviderInfoListener providerInfoListener = config.getProviderInfoListener();
                providerObserver.addProviderListener(config, providerInfoListener);

                EventListener eventListener = event -> {
                    if (event instanceof NamingEvent) {
                        NamingEvent namingEvent = (NamingEvent) event;
                        List<Instance> instances = namingEvent.getInstances();
                        // avoid npe
                        if (null == instances) {
                            instances = new ArrayList<Instance>();
                        }
                        instances.removeIf(i -> !i.isEnabled());
                        providerObserver.updateProviders(config, instances);
                    }
                };
                namingService.subscribe(serviceName, defaultCluster, eventListener);
                consumerListeners.put(config, eventListener);

                List<Instance> allInstances = namingService.getAllInstances(serviceName, defaultCluster);

                List<ProviderInfo> providerInfos = NacosRegistryHelper.convertInstancesToProviders(allInstances);
                List<ProviderInfo> matchProviders = RegistryUtils.matchProviderInfos(config, providerInfos);
                return Collections.singletonList(new ProviderGroup().addAll(matchProviders));
            } catch (SofaRpcRuntimeException e) {
                throw e;
            } catch (Exception e) {
                throw new SofaRpcRuntimeException(LogCodes.getLog(LogCodes.ERROR_SUB_PROVIDER, EXT_NAME), e);
            }

        }

        return null;
    }
Instantiates a new Nacos registry.

@param registryConfig the registry config
registry/registry-nacos/src/main/java/com/alipay/sofa/rpc/registry/nacos/NacosRegistry.java