当前位置:网站首页>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
边栏推荐
- 我想请教下各位大佬,cdc采集mysql时,如果发生了主从切换,有什么方案可以处理吗
- 服务器在线测速系统源码
- WPF layout controls are scaled up and down with the window, which is suitable for multi-resolution full screen filling applications
- 1331. Array sequence number conversion
- Quickly deploy mqtt clusters on AWS using terraform
- How to use JWT for authentication and authorization
- 对话庄表伟:开源第一课
- Ten thousand words detailed Google play online application standard package format AAB
- Flutter tutorial flutter navigator 2.0 with gorouter, use go_ Router package learn about the declarative routing mechanism in fluent (tutorial includes source code)
- Solutions to slow start of MATLAB
猜你喜欢

保障邮箱安全,验证码四个优势

对话庄表伟:开源第一课

Cvpr2021 pedestrian re identification /person re identification paper + summary of open source code

LabVIEW AI visual Toolkit (non Ni vision) download and installation tutorial

Open source huizhichuang future | 2022 open atom global open source summit openatom openeuler sub forum was successfully held

Byte side: how to realize reliable transmission with UDP?

Three methods of using unity mouse to drive objects

Ten thousand words detailed Google play online application standard package format AAB

An example of the mandatory measures of Microsoft edge browser tracking prevention

拥抱开源指南
随机推荐
R language uses LM function to build regression model with interactive items, and uses: sign (colon) to represent the interaction of variables (colon is pure multiplication, excluding the constituent
Guys, ask me, this can't be checkpoint, because there is a JDBC task whose task status is finished,
Techniques for visualizing large time series.
从零开始Blazor Server(2)--整合数据库
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
Cvpr2021 pedestrian re identification /person re identification paper + summary of open source code
Summary of common RSA related problems in CTF: basic RSA encryption and decryption
接口测试的作用
R language uses oneway The test function performs one-way ANOVA
Google Earth Engine——使用geetool批量下载单景影像以Landsat 8 反演后的NDSI结果
How to effectively implement a rapid and reasonable safety evacuation system in hospitals
Introduction to web security RADIUS protocol application
[geek challenge 2019] babysql-1 | SQL injection
A natural choice
Let me think about Linear Algebra: a summary of basic learning of linear algebra
Two point, three point, 01 point plan [bullet I]
什么样的知识付费系统功能,更有利于平台与讲师发展?
[half understood] zero value copy
R language ggplot2 visualization: ggdensity function of ggpubr package visualizes density graph and uses stat_ overlay_ normal_ Density function superimposes positive distribution curve, custom config
中国业务型CDP白皮书 | 爱分析报告