@Override
    public void watchInstances(final String watchKey, final ChangedEventListener listener) {
        try {
            Map<String, String> serverNodes = client.getKeysMapByPrefix(watchKey);
            serverNodes.forEach((k, v) -> listener.onEvent(k, v, ChangedEventListener.Event.ADDED));
            final Watch.Watcher watcher = this.client.watchKeyChanges(watchKey, Watch.listener(response -> {
                for (WatchEvent event : response.getEvents()) {
                    String value = event.getKeyValue().getValue().toString(UTF_8);
                    String path = event.getKeyValue().getKey().toString(UTF_8);
                    switch (event.getEventType()) {
                        case PUT:
                            if (event.getKeyValue().getCreateRevision() == event.getKeyValue().getModRevision()) {
                                listener.onEvent(path, value, ChangedEventListener.Event.ADDED);
                            } else {
                                listener.onEvent(path, value, ChangedEventListener.Event.UPDATED);
                            }
                            LOGGER.info("watch key {} updated, value is {}", watchKey, value);
                            continue;
                        case DELETE:
                            listener.onEvent(path, value, ChangedEventListener.Event.DELETED);
                            LOGGER.info("watch key {} deleted, key is {}", watchKey, path);
                            continue;
                        default:
                    }
                }
            }));
            watchCache.put(watchKey, watcher);
            LOGGER.info("etcd added watcher for key: {}", watchKey);
        } catch (Exception e) {
            LOGGER.error("etcd client watch key: {} error", watchKey, e);
            throw new ShenyuException(e);
        }
    }
The type Etcd instance register repository.
shenyu-registry/shenyu-registry-etcd/src/main/java/org/apache/shenyu/registry/etcd/EtcdInstanceRegisterRepository.java