当前位置: 首页 > news >正文

Eureka 学习笔记4:客户端 DiscoveryClient

版本 awsVersion = ‘1.11.277’

DiscoveryClient # cacheRefreshTask

// 配置shouldFetchRegistry
if (clientConfig.shouldFetchRegistry()) {// 配置client.refresh.intervalint registryFetchIntervalSeconds = clientConfig.getRegistryFetchIntervalSeconds();// 配置expBackOffBoundint expBackOffBound = clientConfig.getCacheRefreshExecutorExponentialBackOffBound();cacheRefreshTask = new TimedSupervisorTask("cacheRefresh",scheduler,cacheRefreshExecutor,registryFetchIntervalSeconds,TimeUnit.SECONDS,expBackOffBound,new CacheRefreshThread());scheduler.schedule(cacheRefreshTask,registryFetchIntervalSeconds, TimeUnit.SECONDS);
}

shouldFetchRegistry 指定是否从服务端拉取注册列表,默认 true

client.refresh.interval 指定从服务端拉取注册列表的时间间隔,默认 30s

client.cacheRefresh.exponentialBackOffBound 指定从服务端拉取注册列表的最大时间间隔,默认 10

注1:当从服务端拉取注册列表的请求超时(即 TimedSupervisorTask 捕获 TimeoutException 异常时),下一次拉取的时间间隔会成倍递增,递增后的时间间隔不能超过 client.cacheRefresh.exponentialBackOffBoundclient.refresh.interval 的乘积(即拉取的时间间隔最大不能超过 10x30=300s)

注2
supervisor

/ˈsuːpəvaɪzə®/

/ˈsuːpərvaɪzər/
n.
监督人;主管人;指导者

注3
exponential

/ˌekspəˈnenʃl/

/ˌekspəˈnenʃl/
adj.
指数的;幂的;越来越快的;由指数表示的
n.
指数


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 指定是否向服务端注册实例,默认 true

lease.renewalInterval 指定向服务端续约的时间间隔,默认 30s

lease.duration 指定向服务端续约的租期时间,默认 90s

client.heartbeat.exponentialBackOffBound 指定向服务端续约的最大时间间隔,默认 10

注1:当向服务端续约的请求超时(即 TimedSupervisorTask 捕获 TimeoutException 异常时),下一次进行续约的时间间隔会成倍递增,递增后的时间间隔不能超过 client.heartbeat.exponentialBackOffBoundlease.renewalInterval 的乘积(即进行续约的时间间隔最大不能超过 10x30=300s)


DiscoveryClient # instanceInfoReplicator

// 配置registration.enabled
if (clientConfig.shouldRegisterWithEureka()) {// ...instanceInfoReplicator = new InstanceInfoReplicator(this,instanceInfo,// 配置appinfo.replicate.intervalclientConfig.getInstanceInfoReplicationIntervalSeconds(),// burstSize2);statusChangeListener = new ApplicationInfoManager.StatusChangeListener(){@Overridepublic void notify(StatusChangeEvent statusChangeEvent) {instanceInfoReplicator.onDemandUpdate();}};// 配置shouldOnDemandUpdateStatusChangeif (clientConfig.shouldOnDemandUpdateStatusChange()) {applicationInfoManager.registerStatusChangeListener(statusChangeListener);}instanceInfoReplicator.start(// 配置appinfo.initial.replicate.timeclientConfig.getInitialInstanceInfoReplicationIntervalSeconds());
}

registration.enabled 指定是否向服务端注册实例,默认 true

appinfo.replicate.interval 指定向服务端注册实例的时间间隔,默认 30s

appinfo.initial.replicate.time 指定初次向服务端注册实例的延迟时间,默认 40s

shouldOnDemandUpdateStatusChange 指定是否启用 StatusChangeListener,在实例状态更新时向服务端注册实例,默认 true


客户端通过 InstanceInfoReplicator 向服务端注册实例,有以下两种方式:

  1. scheduler 周期地异步执行 InstanceInfoReplicator 的 run 方法
public void run() {try {// 刷新实例信息discoveryClient.refreshInstanceInfo();Long dirtyTimestamp = instanceInfo.isDirtyWithTime();// 如果实例信息发生了更新if (dirtyTimestamp != null) {// 向服务端注册实例discoveryClient.register();// 重置实例的dirty状态instanceInfo.unsetIsDirty(dirtyTimestamp);}} catch (Throwable t) {} finally {// scheduler进行下一次延迟调度Future next = scheduler.schedule(this, replicationIntervalSeconds, TimeUnit.SECONDS);scheduledPeriodicRef.set(next);}
}
  1. 实例状态发生变化时,statusChangeListener 同步触发 InstanceInfoReplicator 的 onDemandUpdate 方法,scheduler 异步执行 InstanceInfoReplicator 的 run 方法
public boolean onDemandUpdate() {// 令牌桶限流,如果rateLimiter成功获取令牌if (rateLimiter.acquire(burstSize, allowedRatePerMinute)) {// 如果scheduler没有关闭if (!scheduler.isShutdown()) {scheduler.submit(new Runnable() {@Overridepublic void run() {Future latestPeriodic = scheduledPeriodicRef.get();// 如果scheduler正在执行则取消if (latestPeriodic != null && !latestPeriodic.isDone()) {latestPeriodic.cancel(false);}InstanceInfoReplicator.this.run();}});return true;} // end if (!scheduler.isShutdown())} // end if (rateLimiter.acquire(burstSize, allowedRatePerMinute))
}
http://www.lryc.cn/news/106206.html

相关文章:

  • 【方法】PDF可以转换成Word文档吗?如何操作?
  • AlphaControls crack
  • 论文笔记——Influence Maximization in Undirected Networks
  • Stable Diffusion - SDXL 1.0 全部样式设计与艺术家风格的配置与提示词
  • Hbase pe 压测 OOM问题解决
  • 问题解决——datagrip远程连接虚拟机中ubuntu的mysql失败
  • 【晚风摇叶之随机密码生成器】随机生成密码
  • Spring Cache
  • em3288 linux_4.19 sd卡调试
  • 前端vue uni-app cc-countdown倒计时组件
  • fifo读写的数据个数
  • Java之Map接口
  • windows系统中的命令行可以用python,pip等命令(已在系统中添加过python环境变量),但是pycharm的terminal中无法使用。
  • 编译 OneFlow 模型
  • 【kubernetes】k8s单master集群环境搭建及kuboard部署
  • 0802|IO进程线程 day5 进程概念
  • 4 Promethues监控主机和容器
  • 亚马逊买家账号ip关联怎么处理
  • NO4 实验四:生成Web工程
  • 【linux】进程
  • 电商高并发设计之SpringBoot整合Redis实现布隆过滤器
  • SpringBoot第25讲:SpringBoot集成MySQL - MyBatis 注解方式
  • 服务器返回 413 Request Entity Too Large
  • 如何一目了然地监控远程 Linux 系统
  • 9.环境对象和回调函数
  • 51单片机(普中HC6800-EM3 V3.0)实验例程软件分析概览
  • ubuntu18.04 安装php7.4-xdebug
  • java 定时任务不按照规定时间执行
  • Android复习(Android基础-四大组件)—— Activity
  • Linux系统安装部署MongoDB完整教程(图文详解)