前面的文章中我们着重讲了服务的注册和主动查询服务列表的功能。实际上在客户端发起服务查询(订阅)后,服务端会定时推送服务的结果给客户端,在1.1.4版本中是通过udp的方式推动的
初始化
public PushReceiver(HostReactor hostReactor) {
try {
this.hostReactor = hostReactor;
udpSocket = new DatagramSocket();
executorService = new ScheduledThreadPoolExecutor(1, new ThreadFactory() {
@Override
public Thread newThread(Runnable r) {
Thread thread = new Thread(r);
thread.setDaemon(true);
thread.setName("com.alibaba.nacos.naming.push.receiver");
return thread;
}
});
executorService.execute(this);
} catch (Exception e) {
NAMING_LOGGER.error("[NA] init udp socket failed", e);
}
}
PushServer 初始化一个udpSocket server ,创建单线程的线程池用于监听和处理服务端发来的消息。hostReactor 服务处理服务相关的逻辑

最低0.47元/天 解锁文章
1321

被折叠的 条评论
为什么被折叠?



