当前位置:网站首页>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
边栏推荐
- How to use JWT for authentication and authorization
- Thinkphp5行为钩子Hook返回结果(数据)示例
- Blackboard cleaning effect shows H5 source code + very romantic / BGM attached
- 完整版H5社交聊天平台源码[完整数据库+完整文档教程]
- 融云 IM & RTC 能力上新盘点
- 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
- Install SSL Certificate in Litespeed web server
- R language ggplot2 visualization: use the ggboxplot function of ggpubr package to visualize the box diagram and customize the fill parameter to configure the filling color of the box
- Byte side: how to realize reliable transmission with UDP?
- What kind of knowledge payment system functions are more conducive to the development of the platform and lecturers?
猜你喜欢

Refresh your understanding of redis cluster
![[general database integrated development environment] Shanghai daoning provides you with Aqua Data Studio downloads, tutorials, and trials](/img/46/830b7703ae7cbfa6051137061560c2.png)
[general database integrated development environment] Shanghai daoning provides you with Aqua Data Studio downloads, tutorials, and trials

Rongyun IM & RTC capabilities on new sites
![[pyGame practice] when the end of the world comes, how long can you live in a cruel survival game that really starts from scratch?](/img/2b/1eb02249ab9ad0b4e1bfeeee87418c.png)
[pyGame practice] when the end of the world comes, how long can you live in a cruel survival game that really starts from scratch?

服务器在线测速系统源码

Jupiter、spyder、Anaconda Prompt 、navigator 快捷键消失的解决办法

In order to ensure the normal operation of fire-fighting equipment in large buildings, the power supply monitoring system of fire-fighting equipment plays a key role

How to effectively implement a rapid and reasonable safety evacuation system in hospitals

Techniques for visualizing large time series.

Autumn recruit offer harvesters, and take the offers of major manufacturers at will
随机推荐
天狼星网络验证源码/官方正版/内附搭建教程
AlexNet—论文分析及复现
echo -ne(echo line)
Who's the big God help? Let's see how Oracle number type parsing works. Struct{scale=15, Val
AlexNet—论文分析及复现
Today's sleep quality record 74 points
Has samesite cookies ever occurred when using identityserver?
拥抱开源指南
目标检测领域必看的6篇论文
Six papers that must be seen in the field of target detection
Let me think about Linear Algebra: a summary of basic learning of linear algebra
[general database integrated development environment] Shanghai daoning provides you with Aqua Data Studio downloads, tutorials, and trials
Thinkphp5行为钩子Hook返回结果(数据)示例
「以云为核,无感极速」第五代验证码重磅来袭
Rongyun IM & RTC capabilities on new sites
我想请教下各位大佬,cdc采集mysql时,如果发生了主从切换,有什么方案可以处理吗
R language uses dplyr package group_ By function and summarize function calculate the mean value of all covariates involved in the analysis based on grouped variables (difference in means of covariate
保障邮箱安全,验证码四个优势
[geek challenge 2019] babysql-1 | SQL injection
Jupiter、spyder、Anaconda Prompt 、navigator 快捷键消失的解决办法