版本:4.2.0
producer与nameServer建立连接主要是拉取topic路由信息
MQClientInstance启动的时候会启动一个定时任务
this.scheduledExecutorService.scheduleAtFixedRate(new Runnable() {
public void run() {
try {
MQClientInstance.this.updateTopicRouteInfoFromNameServer();
} catch (Exception var2) {
MQClientInstance.this.log.error("ScheduledTask updateTopicRouteInfoFromNameServer exception", var2);
}
}
}, 10L, (long)this.clientConfig.getPollNameServerInterval(), TimeUnit.MILLISECONDS);
深入了解一下这个任务在做什么
public void updateTopicRouteInfoFromNameServer() {
Set<String> topicList = new HashSet();
Iterator i$ = this.consumerTable.entrySet().iterator();
while(true) {
Set subList;
do {
MQConsumerInner impl;
do {
Entry entry;
if (!i$.hasNext()) {
i$ = this.producerTable.entrySet().iterator();
while(i$.hasNext()) {
entry = (Entry)i$.next();
MQProducerInner impl = (MQProducerInner)entry.getValue();
if (impl != null) {
subList = impl.getPublishTopicList();
topicList.addAll(subList);
}
}
i$ = topicList.iterator();