Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

如何使用心跳机制? #126

Open
hjx777 opened this issue Dec 5, 2022 · 4 comments
Open

如何使用心跳机制? #126

hjx777 opened this issue Dec 5, 2022 · 4 comments

Comments

@hjx777
Copy link

hjx777 commented Dec 5, 2022

您好,请问注册一个临时实例,如何使用心跳验证的方式保证实例正常呢?样例中没有这样的demo。或许是应该直接使用BeatReactor.h提供的函数?如果方便得话,还请告知,万分感谢。

@hjx777
Copy link
Author

hjx777 commented Dec 6, 2022

查看了之前的回复,使用临时实例会带有心跳机制,使用NacosNamingService.cpp中的registerInstance(const NacosString &serviceName,const NacosString &groupName,Instance &instance)完成注册,拥有beat信息,但不知道如何使用。注册成功之后在15s后会变成不健康实例,后续被删除。我有两个使用想法,由于对c++掌握程度有限,所以不知道是否正确:

  1. 直接使用BeatTask中run函数,函数中包含sendbeat,应该是实现心跳发送的代码;
  2. 使用NamingProxy下的sendbeat函数
    但是我不知道这样是否可行,目前仅需要注册和发送心跳【使用临时实例,使用持久实例出现直接就是非健康实例问题】。我在text中没有找到相似的测试代码,如果能够提供具体说明,将会万分感谢。

@xiedeacc
Copy link

+1, 就不能提供一个心跳demo吗

@xiedeacc
Copy link

看了代码后发现,NamingService对象不要析构掉就会定期自动发心跳,nacos::ResourceGuardnacos::NamingService把NamingService指针包好后,处理的不好就会把NamingService析构掉,就没法自动发心跳了

@lzhprigrammer
Copy link

注册中心要能够实时知道各个服务实例的状态,通过心跳机制来实现,实例定时向注册中心发送请求,表明自己还活着,如果心跳没了,注册中心就可以对其清理。

为啥不是在你们注册的服务内调用sendbeat 呢?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants