当前位置:网站首页>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
边栏推荐
- The fifth generation verification code of "cloud centered, insensitive and extremely fast" is coming heavily
- Shell (I)
- [geek challenge 2019] babysql-1 | SQL injection
- PHP detects whether the URL URL link is normally accessible
- Unity鼠标带动物体运动的三种方法
- Ten thousand words detailed Google play online application standard package format AAB
- 学会使用MySQL的Explain执行计划,SQL性能调优从此不再困难
- [applet] how to notify users of wechat applet version update?
- Refresh your understanding of redis cluster
- Display line number under VIM command [easy to understand]
猜你喜欢

Top ten application development trends from 2022 to 2023

A lock faster than read-write lock. Don't get to know it quickly

Will PFP be the future of digital collections?

服务器在线测速系统源码

Understand how to prevent tampering and hijacking of device fingerprints

【一知半解】零值拷贝

Good use explosion! The idea version of postman has been released, and its functions are really powerful

Design a system that supports millions of users

Five Ali technical experts have been offered. How many interview questions can you answer

Autumn recruit offer harvesters, and take the offers of major manufacturers at will
随机推荐
R language - some metrics for unbalanced data sets
Summary of common RSA related problems in CTF: basic RSA encryption and decryption
MySQL离线同步到odps的时候 可以配置动态分区吗
【一知半解】零值拷贝
Dialogue with Zhuang biaowei: the first lesson of open source
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
Will PFP be the future of digital collections?
擦黑板特效表白H5源码+非常浪漫/附BGM
Five Ali technical experts have been offered. How many interview questions can you answer
什么样的知识付费系统功能,更有利于平台与讲师发展?
R language ggplot2 visualization: use the ggdotplot function of ggpubr package to visualize dot plot, set the add parameter, add violin graph to the dot plot, and add the vertical line of mean standar
Shell (II)
Using C language to realize bidirectional linked list
Boutique scheme | Haitai Fangyuan full stack data security management scheme sets a "security lock" for data
Ripro9.0 revised and upgraded version +wp two beautification packages + rare plug-ins
How to use JWT for authentication and authorization
Update dev (development version) of the latest win11
保障邮箱安全,验证码四个优势
Learning notes tree array
Leecode8 string conversion integer (ATOI)