Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nacos subscribe #13069

Open
JacianZhu opened this issue Jan 24, 2025 · 0 comments
Open

nacos subscribe #13069

JacianZhu opened this issue Jan 24, 2025 · 0 comments

Comments

@JacianZhu
Copy link

环境 : nacos 客户端版本2.3.2 服务端maven依赖2.2.1

environment Nacos client version 2.3.2 server Maven dependency 2.2.1

实现的功能: 动态监听微服务的上下线 通过subscribe

Implemented function: Dynamically monitor the online and offline of microservices through subscribe

注册的永久实例 通过/health 健康检查 2.3.2的版本监听不到服务的变化
The registered permanent instance cannot detect changes in the service through version 2.3.2 of/health health check

private EventListener buildEventListener() {
    return event -> {
        if (event instanceof NamingEvent namingEvent) {
            String serviceName = namingEvent.getServiceName();
            List<Instance> newInstances = namingEvent.getInstances();
            newInstances.forEach(instance -> {
                String instanceKey = instance.getIp() + ":" + instance.getPort();
                boolean isHealthy = isInstanceHealthy(nacosServerAddr, nameSpace, serviceName, instance.getIp(), instance.getPort());
                if (isHealthy) {
                    log.info("Service health status changed to healthy: {} -> {}", serviceName, instanceKey);
                } else {
                    log.info("Service health status changed to unhealthy: {} -> {}", serviceName, instanceKey);
                    sendServiceNotification(serviceName, instanceKey, false);
                }
            });
        }
    };
}

Image

但是很奇怪的是 用客户端版本2.2.1 可以监听到变化
But it's strange that changes can be detected using client version 2.2.1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants