Source entrance
ConfigFactory.createConfigService
ConfigService configService = NacosFactory.createConfigService(properties);
String content = configService.getConfig(dataId,groupId,3000);
Factory construction by ConfigService
Decorator MetricsHttpAgent package http requests, increase monitoring
agent-> http proxy way to initiate a request clientWorker -> specific work-related
NacosConfigService.NacosConfigService
this.agent = new MetricsHttpAgent(new ServerHttpAgent(properties));
this.agent.start();
this.worker = new ClientWorker(this.agent, this.configFilterChainManager, properties);
-
The agency created a httpAgent -> http request initiated
-
We created a clientWorker-> asynchronous thread (cron job)
this.executor.scheduleWithFixedDelay(new Runnable() {
public void run() {
try {
ClientWorker.this.checkConfigInfo();
} catch (Throwable var2) {
ClientWorker.LOGGER.error("[" + agent.getName() + "] [sub-check] rotate check error", var2);
}
}
}, 1L, 10L, TimeUnit.MILLISECONDS);
How many requests to do long polling?
Batch processing
public void checkConfigInfo() {
//分任务
int listenerSize = ((Map)this.cacheMap.get()).size();
//向上取整
int longingTaskCount = (int)Math.ceil((double)listenerSize / ParamUtil.getPerTaskConfigSize());
if ((double)longingTaskCount > this.currentLongingTaskCount) {
for(int i = (int)this.currentLongingTaskCount; i < longingTaskCount; ++i) {
// To determine whether or not to perform this task need to think about the task list is now a disorderly process of change may be a problem
the this. ExecutorService. the Execute ( new new ClientWorker. LongPollingRunnable ( i));
} . the this currentLongingTaskCount = ( Double) longingTaskCount; } }
Check the local configuration monitor ->
Check cache MD5
Check the updated file
ClientWorker.this.checkLocalConfig(cacheData);
if (cacheData.isUseLocalConfigInfo()) {
cacheData.checkListenerMd5();
}
Check the remote
List<String> changedGroupKeys = ClientWorker.this.checkUpdateDataIds(cacheDatas, inInitializingCacheList);
Iterator var16 = changedGroupKeys.iterator();
groupId + dataId + tenant remotely check
ClientWorker.this.getServerConfig(dataId, group, tenant, 3000L);
void checkListenerMd5() {
Iterator var1 = this.listeners.iterator();
while(var1.hasNext()) {
ManagerListenerWrap wrap = (ManagerListenerWrap)var1.next();
if (!this.md5.equals(wrap.lastCallMd5)) {
this.safeNotifyListener(this.dataId, this.group, this.content, this.md5, wrap);
}
}
}
Get Configuration
Get to go to a local, if not go to take remote configuration
content = LocalConfigInfoProcessor.getFailover(this.agent.getName(), dataId, group, tenant);
if (content != null) {
cr.setContent(content);
} else {
content = this.worker.getServerConfig(dataId, group, tenant, timeoutMs);
}