@Override
    public void watchInstances(final String key, final ChangedEventListener listener) {
        try {
            List<Instance> initialInstances = namingService.selectInstances(key, groupName, true);
            instanceListMap.put(key, initialInstances);
            for (Instance instance : initialInstances) {
                listener.onEvent(key, buildUpstreamJsonFromInstance(instance), ChangedEventListener.Event.ADDED);
            }
            EventListener nacosListener = event -> {
                if (event instanceof NamingEvent) {
                    try {
                        List<Instance> previousInstances = instanceListMap.get(key);
                        List<Instance> currentInstances = namingService.selectInstances(key, groupName, true);
                        compareInstances(previousInstances, currentInstances, listener);
                        instanceListMap.put(key, currentInstances);
                    } catch (NacosException e) {
                        throw new ShenyuException(e);
                    }
                }
            };
            namingService.subscribe(key, groupName, nacosListener);
            listenerMap.put(key, nacosListener);
            LOGGER.info("nacos registry subscribed to nacos updates for key: {}", key);
        } catch (NacosException e) {
            LOGGER.error("nacos registry error watching key: {}", key, e);
            throw new ShenyuException(e);
        }
    }
The type Nacos instance register repository.
shenyu-registry/shenyu-registry-nacos/src/main/java/org/apache/shenyu/registry/nacos/NacosInstanceRegisterRepository.java