当前位置:网站首页>Client service registration of Nacos registry
Client service registration of Nacos registry
2022-07-28 11:45:00 【InfoQ】
4 nacos Client service registration of the registry
register() Method
public void register(Registration registration) {
if (StringUtils.isEmpty(registration.getServiceId())) {
log.warn("No service to register for nacos client...");
} else {
String serviceId = registration.getServiceId();
String group = this.nacosDiscoveryProperties.getGroup();
Instance instance = this.getNacosInstanceFromRegistration(registration);
try {
this.namingService.registerInstance(serviceId, group, instance);
log.info("nacos registry, {} {} {}:{} register finished", new Object[]{group, serviceId, instance.getIp(), instance.getPort()});
} catch (Exception var6) {
log.error("nacos registry, {} register failed...{},", new Object[]{serviceId, registration.toString(), var6});
ReflectionUtils.rethrowRuntimeException(var6);
}
}
}
registerInstance() Method :
@Override
public void registerInstance(String serviceName, String groupName, Instance instance) throws NacosException {
if (instance.isEphemeral()) {
BeatInfo beatInfo = new BeatInfo();
beatInfo.setServiceName(NamingUtils.getGroupedName(serviceName, groupName));
beatInfo.setIp(instance.getIp());
beatInfo.setPort(instance.getPort());
beatInfo.setCluster(instance.getClusterName());
beatInfo.setWeight(instance.getWeight());
beatInfo.setMetadata(instance.getMetadata());
beatInfo.setScheduled(false);
long instanceInterval = instance.getInstanceHeartBeatInterval();
beatInfo.setPeriod(instanceInterval == 0 ? DEFAULT_HEART_BEAT_INTERVAL : instanceInterval);
beatReactor.addBeatInfo(NamingUtils.getGroupedName(serviceName, groupName), beatInfo);
}
serverProxy.registerService(NamingUtils.getGroupedName(serviceName, groupName), groupName, instance);
}
- First, create BeatInfo object , And fill in the relevant attribute information ,BeatInfo Is to save the relevant information of the instance heartbeat , Include ip Address 、 Port number 、 In the cluster 、 Weight information, etc
- adopt beatReactor.addBeatInfo Create heartbeat information to realize health monitoring , Parameters have ServiceName、groupName And heartbeat instance objects , So as to determine which service and which group are the following instances ,Naocs Server You must ensure that the registered service instance is healthy , And heartbeat detection is the means to serve health testing
- serverProxy.registerService Implement service registration .
addBeatInfo Method :
public void addBeatInfo(String serviceName, BeatInfo beatInfo) {
NAMING_LOGGER.info("[BEAT] adding beat: {} to beat map.", beatInfo);
String key = buildKey(serviceName, beatInfo.getIp(), beatInfo.getPort());
BeatInfo existBeat = null;
//fix #1733
if ((existBeat = dom2Beat.remove(key)) != null) {
existBeat.setStopped(true);
}
dom2Beat.put(key, beatInfo);
executorService.schedule(new BeatTask(beatInfo), beatInfo.getPeriod(), TimeUnit.MILLISECONDS);
MetricsMonitor.getDom2BeatSizeMonitor().set(dom2Beat.size());
}
registerService() Method
summary
边栏推荐
- LabVIEW AI视觉工具包(非NI Vision)下载与安装教程
- Introduction to web security RADIUS protocol application
- LabVIEW AI visual Toolkit (non Ni vision) download and installation tutorial
- Byte side: how to realize reliable transmission with UDP?
- Will PFP be the future of digital collections?
- WPF layout controls are scaled up and down with the window, which is suitable for multi-resolution full screen filling applications
- 哪位大神帮看下 oracle number类型解析 怎么搞 Struct{scale=15,val
- Random talk on GIS data (V) - geographic coordinate system
- Database advanced learning notes -- object type
- R language ggplot2 visualization: use the ggdotplot function of ggpubr package to visualize the grouped dot plot, set the palette parameter, and set the color of data points in different grouped dot p
猜你喜欢

服务器在线测速系统源码

Game theory 1. Introduction (basic concepts of combination games, confrontation search, bash games, Nim games)

Function of interface test

What functions does MySQL have? Don't look everywhere. Just look at this.

CVPR2021 行人重识别/Person Re-identification 论文+开源代码汇总

Refresh your understanding of redis cluster

CVPR2020 best paper:对称可变形三维物体的无监督学习

对话庄表伟:开源第一课

Zotero document manager and its use posture (updated from time to time)

What is the process of switching c read / write files from user mode to kernel mode?
随机推荐
万字详解 Google Play 上架应用标准包格式 AAB
Shell (I)
对话庄表伟:开源第一课
学会使用MySQL的Explain执行计划,SQL性能调优从此不再困难
从零开始Blazor Server(2)--整合数据库
outlook突然变得很慢很卡怎么解决
大佬们,问下,这个不能checkpoint,因为有个jdbc的task任务状态是FINISHED,
[极客大挑战 2019]BabySQL-1|SQL注入
[cesium] entity property and timing binding: the sampledproperty method is simple to use
How to deal with invalid objects monitored by Oracle every day in the production environment?
echo -ne(echo line)
Will PFP be the future of digital collections?
[collection] Advanced Mathematics: Capriccio of stars
Four advantages of verification code to ensure mailbox security
ASP. Net core 6 framework unveiling example demonstration [29]: building a file server
R language uses LM function to build regression model and regression model for transformed data (for example, it is necessary to build regression model for X and y, but they have no linear relationshi
Installing sqlmap on win10 (Windows 7)
Postgres overview
Today's sleep quality record 74 points
Cvpr2020 best paper: unsupervised learning of symmetric deformable 3D objects