版本 awsVersion = ‘1.11.277’
DiscoveryClient # cacheRefreshTask
// 配置shouldFetchRegistry
if (clientConfig.shouldFetchRegistry()) {
// 配置client.refresh.interval
int registryFetchIntervalSeconds = clientConfig
.getRegistryFetchIntervalSeconds();
// 配置expBackOffBound
int expBackOffBound = clientConfig
.getCacheRefreshExecutorExponentialBackOffBound();
cacheRefreshTask = new TimedSupervisorTask(
"cacheRefresh",
scheduler,
cacheRefreshExecutor,
registryFetchIntervalSeconds,
TimeUnit.SECONDS,
expBackOffBound,
new CacheRefreshThread()
);
scheduler.schedule(
cacheRefreshTask,
registryFetchIntervalSeconds, TimeUnit.SECONDS);
}
shouldFetchRegistry
指定是否從服務(wù)端拉取注冊(cè)列表,默認(rèn) true
client.refresh.interval
指定從服務(wù)端拉取注冊(cè)列表的時(shí)間間隔,默認(rèn) 30s
client.cacheRefresh.exponentialBackOffBound
指定從服務(wù)端拉取注冊(cè)列表的最大時(shí)間間隔,默認(rèn) 10
注1:當(dāng)從服務(wù)端拉取注冊(cè)列表的請(qǐng)求超時(shí)(即 TimedSupervisorTask 捕獲 TimeoutException 異常時(shí)),下一次拉取的時(shí)間間隔會(huì)成倍遞增,遞增后的時(shí)間間隔不能超過(guò) client.cacheRefresh.exponentialBackOffBound
和 client.refresh.interval
的乘積(即拉取的時(shí)間間隔最大不能超過(guò) 10x30=300s)
注2:
supervisor
英
/?su?p?va?z??/
美
/?su?p?rva?z?r/
n.
監(jiān)督人;主管人;指導(dǎo)者
注3:
exponential
英
/?eksp??nen?l/
美
/?eksp??nen?l/
adj.
指數(shù)的;冪的;越來(lái)越快的;由指數(shù)表示的
n.
指數(shù)
DiscoveryClient # heartbeatTask
if (clientConfig.shouldRegisterWithEureka()) {
int renewalIntervalInSecs = instanceInfo
.getLeaseInfo().getRenewalIntervalInSecs();
int expBackOffBound = clientConfig
.getHeartbeatExecutorExponentialBackOffBound();
heartbeatTask = new TimedSupervisorTask(
"heartbeat",
scheduler,
heartbeatExecutor,
renewalIntervalInSecs,
TimeUnit.SECONDS,
expBackOffBound,
new HeartbeatThread()
);
scheduler.schedule(
heartbeatTask,
renewalIntervalInSecs, TimeUnit.SECONDS);
}
registration.enabled
指定是否向服務(wù)端注冊(cè)實(shí)例,默認(rèn) true
lease.renewalInterval
指定向服務(wù)端續(xù)約的時(shí)間間隔,默認(rèn) 30s
lease.duration
指定向服務(wù)端續(xù)約的租期時(shí)間,默認(rèn) 90s
client.heartbeat.exponentialBackOffBound
指定向服務(wù)端續(xù)約的最大時(shí)間間隔,默認(rèn) 10
注1:當(dāng)向服務(wù)端續(xù)約的請(qǐng)求超時(shí)(即 TimedSupervisorTask 捕獲 TimeoutException 異常時(shí)),下一次進(jìn)行續(xù)約的時(shí)間間隔會(huì)成倍遞增,遞增后的時(shí)間間隔不能超過(guò) client.heartbeat.exponentialBackOffBound
和 lease.renewalInterval
的乘積(即進(jìn)行續(xù)約的時(shí)間間隔最大不能超過(guò) 10x30=300s)
DiscoveryClient # instanceInfoReplicator
// 配置registration.enabled
if (clientConfig.shouldRegisterWithEureka()) {
// ...
instanceInfoReplicator = new InstanceInfoReplicator(
this,
instanceInfo,
// 配置appinfo.replicate.interval
clientConfig.getInstanceInfoReplicationIntervalSeconds(),
// burstSize
2);
statusChangeListener = new ApplicationInfoManager.StatusChangeListener()
{
@Override
public void notify(StatusChangeEvent statusChangeEvent) {
instanceInfoReplicator.onDemandUpdate();
}
};
// 配置shouldOnDemandUpdateStatusChange
if (clientConfig.shouldOnDemandUpdateStatusChange()) {
applicationInfoManager
.registerStatusChangeListener(statusChangeListener);
}
instanceInfoReplicator.start(
// 配置appinfo.initial.replicate.time
clientConfig.getInitialInstanceInfoReplicationIntervalSeconds());
}
registration.enabled
指定是否向服務(wù)端注冊(cè)實(shí)例,默認(rèn) true
appinfo.replicate.interval
指定向服務(wù)端注冊(cè)實(shí)例的時(shí)間間隔,默認(rèn) 30s
appinfo.initial.replicate.time
指定初次向服務(wù)端注冊(cè)實(shí)例的延遲時(shí)間,默認(rèn) 40s
shouldOnDemandUpdateStatusChange
指定是否啟用 StatusChangeListener,在實(shí)例狀態(tài)更新時(shí)向服務(wù)端注冊(cè)實(shí)例,默認(rèn) true文章來(lái)源:http://www.zghlxwxcb.cn/news/detail-618463.html
客戶(hù)端通過(guò) InstanceInfoReplicator 向服務(wù)端注冊(cè)實(shí)例,有以下兩種方式:文章來(lái)源地址http://www.zghlxwxcb.cn/news/detail-618463.html
- scheduler 周期地
異步執(zhí)行
InstanceInfoReplicator 的 run 方法
public void run() {
try {
// 刷新實(shí)例信息
discoveryClient.refreshInstanceInfo();
Long dirtyTimestamp = instanceInfo.isDirtyWithTime();
// 如果實(shí)例信息發(fā)生了更新
if (dirtyTimestamp != null) {
// 向服務(wù)端注冊(cè)實(shí)例
discoveryClient.register();
// 重置實(shí)例的dirty狀態(tài)
instanceInfo.unsetIsDirty(dirtyTimestamp);
}
} catch (Throwable t) {
} finally {
// scheduler進(jìn)行下一次延遲調(diào)度
Future next = scheduler
.schedule(this, replicationIntervalSeconds, TimeUnit.SECONDS);
scheduledPeriodicRef.set(next);
}
}
- 實(shí)例狀態(tài)發(fā)生變化時(shí),statusChangeListener
同步觸發(fā)
InstanceInfoReplicator 的 onDemandUpdate 方法,scheduler異步執(zhí)行
InstanceInfoReplicator 的 run 方法
public boolean onDemandUpdate() {
// 令牌桶限流,如果rateLimiter成功獲取令牌
if (rateLimiter.acquire(burstSize, allowedRatePerMinute)) {
// 如果scheduler沒(méi)有關(guān)閉
if (!scheduler.isShutdown()) {
scheduler.submit(new Runnable() {
@Override
public void run() {
Future latestPeriodic = scheduledPeriodicRef.get();
// 如果scheduler正在執(zhí)行則取消
if (latestPeriodic != null && !latestPeriodic.isDone()) {
latestPeriodic.cancel(false);
}
InstanceInfoReplicator.this.run();
}
});
return true;
} // end if (!scheduler.isShutdown())
} // end if (rateLimiter.acquire(burstSize, allowedRatePerMinute))
}
到了這里,關(guān)于Eureka 學(xué)習(xí)筆記2:客戶(hù)端 DiscoveryClient的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!