当前位置:网站首页>Eureka的InstanceInfoReplicator类(服务注册辅助类)
Eureka的InstanceInfoReplicator类(服务注册辅助类)
2022-06-22 12:38:00 【51CTO】
欢迎访问我的GitHub
这里分类和汇总了欣宸的全部原创(含配套源码): https://github.com/zq2599/blog_demos
关于服务注册
- 以下图片来自 Netflix官方,图中显示Eureka Client会向注册中心发起Get Registry请求来获取服务列表:

- 以Spring Cloud的Edgware.RELEASE版本为例,Eureka client的注册动作是在com.netflix.discovery.DiscoveryClient类的initScheduledTasks方法中执行的,相关代码片段如下所示,请注意中文注释:
- 上述代码表明,将自身信息上报到Eureka server的工作是通过调用instanceInfoReplicator的api完成的;
InstanceInfoReplicator的作用
- 先看InstanceInfoReplicator源码的注释:
- 我的理解:
- InstanceInfoReplicator是个任务类,负责将自身的信息周期性的上报到Eureka server;
- 有两个场景触发上报:周期性任务、服务状态变化(onDemandUpdate被调用),因此,在同一时刻有可能有两个上报的任务同时出现;
- 单线程执行上报的操作,如果有多个上报任务,也能确保是串行的;
- 有频率限制,通过burstSize参数来控制;
- 先创建的任务总是先执行,但是onDemandUpdate方法中创建的任务会将周期性任务给丢弃掉;
源码分析
- 以前面对注释的理解作为主线,去看源码:
- 先看构造方法,如下,中文注释位置需要注意:
- 从以上代码可见,构造方法中准备好了线程池和频率限制工具,再算好了每分钟允许的任务数;
- 在com.netflix.discovery.DiscoveryClient类的initScheduledTasks方法中,通过调用instanceInfoReplicator.start方法启动了周期性任务,现在来看此方法:
- 延时时间到达时,会执行run方法:
- 以上代码汇总起来,就完成了周期性任务的逻辑,接下来看看被外部调用的onDemandUpdate方法:
如上述代码所示,可见之前注释中提到的功能都已实现;
至此,InstanceInfoReplicator已分析完毕,可见这是个功能强大的辅助类,在应用信息上报到Eureka server时发挥了重要的作用,业务逻辑可以放心的提交上报请求,并发、频率超限等情况都被InstanceInfoReplicator处理好了;
欢迎关注51CTO博客:程序员欣宸
边栏推荐
- 6月《中国数据库行业分析报告》发布!智能风起,列存更生
- Leetcode union search set
- Getting started with shell Basics
- RF5.0新内容速看
- RobotFramework二次开发——实时日志
- Query rewriting for opengauss kernel analysis
- 448. Find All Numbers Disappeared in an Array
- Starting Oracle under Linux
- 155. Min Stack
- Acwing 241 Loulan totem (detailed explanation of tree array)
猜你喜欢

Système de classification des déchets et de gestion des transports basé sur SSM, exemple de thèse de diplôme de haute qualité (peut être utilisé directement), code source, script de base de données, t

Getting started with shell Basics

Uninstall MySQL 8

HMS Core新闻行业解决方案:让技术加上人文的温度

130. Surrounded Regions

别再用 System.currentTimeMillis() 统计耗时了,太 Low,StopWatch 好用到爆!

leetcode 85. Max rectangle

Redis password modification, startup, view and other operations

leetcode-子序列/子串问题

310. Minimum Height Trees
随机推荐
Problème de sous - séquence / substrat leetcode
Andrdoid delay operation
Leetcode subsequence / substring problem
Getting started with shell Basics
MySQL中的存储过程
Query rewriting for opengauss kernel analysis
Leetcode knapsack problem
leetcode 99.恢复二叉搜索树
leetcode 834. Sum of distances in the tree
leetcode LCP 10. Binary tree task scheduling
Using Sqlalchemy for combined paging queries
240. Search a 2D Matrix II
Acwing week 52
934. Shortest Bridge
Leetcode daily question 202110
别再用 System.currentTimeMillis() 统计耗时了,太 Low,StopWatch 好用到爆!
Oracle stored procedure 2
Secondary development of robotframework - real time log
268. Missing Number
openGauss内核分析之查询重写