国产 无码 综合区,色欲AV无码国产永久播放,无码天堂亚洲国产AV,国产日韩欧美女同一区二区

Eureka 學(xué)習(xí)筆記2:客戶(hù)端 DiscoveryClient

這篇具有很好參考價(jià)值的文章主要介紹了Eureka 學(xué)習(xí)筆記2:客戶(hù)端 DiscoveryClient。希望對(duì)大家有所幫助。如果存在錯(cuò)誤或未考慮完全的地方,請(qǐng)大家不吝賜教,您也可以點(diǎn)擊"舉報(bào)違法"按鈕提交疑問(wèn)。

版本 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.exponentialBackOffBoundclient.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.exponentialBackOffBoundlease.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


客戶(hù)端通過(guò) InstanceInfoReplicator 向服務(wù)端注冊(cè)實(shí)例,有以下兩種方式:文章來(lái)源地址http://www.zghlxwxcb.cn/news/detail-618463.html

  1. 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);
    }
}
  1. 實(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)!

本文來(lái)自互聯(lián)網(wǎng)用戶(hù)投稿,該文觀點(diǎn)僅代表作者本人,不代表本站立場(chǎng)。本站僅提供信息存儲(chǔ)空間服務(wù),不擁有所有權(quán),不承擔(dān)相關(guān)法律責(zé)任。如若轉(zhuǎn)載,請(qǐng)注明出處: 如若內(nèi)容造成侵權(quán)/違法違規(guī)/事實(shí)不符,請(qǐng)點(diǎn)擊違法舉報(bào)進(jìn)行投訴反饋,一經(jīng)查實(shí),立即刪除!

領(lǐng)支付寶紅包贊助服務(wù)器費(fèi)用

相關(guān)文章

覺(jué)得文章有用就打賞一下文章作者

支付寶掃一掃打賞

博客贊助

微信掃一掃打賞

請(qǐng)作者喝杯咖啡吧~博客贊助

支付寶掃一掃領(lǐng)取紅包,優(yōu)惠每天領(lǐng)

二維碼1

領(lǐng)取紅包

二維碼2

領(lǐng)紅包