Deprecated: imwpcache\f884414bce24ee67f\f73723ec7b1919fa5::__construct(): Implicitly marking parameter $YECBGYFECGEAFWHA as nullable is deprecated, the explicit nullable type must be used instead in /www/wwwroot/www.chuangxiangniao.com/wp-content/plugins/imwpcache-dist/build/f884414bce24ee67ff73723ec7b1919fa5.php on line 2

Deprecated: imwpcache\f884414bce24ee67f\f73723ec7b1919fa5::__construct(): Implicitly marking parameter $BBWFDDBHHYHDXXAB as nullable is deprecated, the explicit nullable type must be used instead in /www/wwwroot/www.chuangxiangniao.com/wp-content/plugins/imwpcache-dist/build/f884414bce24ee67ff73723ec7b1919fa5.php on line 2
Python项目Nacos注册失败,健康实例数不稳定怎么办?_创想鸟

Python项目Nacos注册失败,健康实例数不稳定怎么办?

python项目nacos注册失败,健康实例数不稳定怎么办?

python项目注册nacos,健康实例数不稳定的原因分析

问题描述:
使用tornado框架向2.0版本的nacos注册服务并发送心跳,但发现健康实例数在nacos管理页面上不稳定。

原因分析:

经过分析,原因在于使用了2.x版本的nacos api,而python sdk一直没有支持2.x版本。因此,当使用v2版本的api发送心跳时,会出现健康实例数不稳定的问题。

立即学习“Python免费学习笔记(深入)”;

解决方案:

修改项目中的nacos相关接口,使用v1版本的api进行注册、发送心跳和注销操作。

具体修改:

将register、send_beat和deregister方法中的url路径从/nacos/v2/ns/instance修改为/nacos/v1/ns/instance。

修改后的代码示例:

async def register(self, service_name, port, cluster_name='default', weight=1.0, metadata=None,                       enable=True, healthy=True, ephemeral=True, group_name=DEFAULT_GROUP_NAME):    url = '/nacos/v1/ns/instance'    params = {        'ip': self.service_ip,        'port': port,        'serviceName': service_name,        'weight': weight,        'enable': enable,        'healthy': healthy,        'clusterName': cluster_name,        'ephemeral': ephemeral,        'groupName': group_name,        'namespaceId': self.namespace,        'username': self.username,        'password': self.password    }    self._build_metadata(metadata, params)    ...async def send_beat(self, service_name, port, cluster_name='default', weight=1.0,                        ephemeral=True, group_name=DEFAULT_GROUP_NAME):    url = '/nacos/v1/ns/instance/beat'    beat_data = {        'serviceName': f'{group_name}@@{service_name}',        'ip': self.service_ip,        'port': port,        'weight': weight,        'ephemeral': ephemeral,        'cluster': cluster_name    }    params = {        'serviceName': f'{group_name}@@{service_name}',        'beat': json.dumps(beat_data),        'groupName': group_name,        'namespaceId': self.namespace,        'username': self.username,        'password': self.password    }    ...async def deregister(self, service_name, port, cluster_name='default', ephemeral=True, group_name=DEFAULT_GROUP_NAME):    url = '/nacos/v1/ns/instance'    params = {        'serviceName': service_name,        'ip': self.service_ip,        'port': port,        'namespaceId': self.namespace,        'healthy': True,        'username': self.username,        'password': self.password,        'ephemeral': ephemeral,        'groupName': group_name,        'clusterName': cluster_name    }    ...

注意:

修改接口后,需要重启项目,以确保使用新的v1版本api。

以上就是Python项目Nacos注册失败,健康实例数不稳定怎么办?的详细内容,更多请关注创想鸟其它相关文章!

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。
如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至 chuangxiangniao@163.com 举报,一经查实,本站将立刻删除。
发布者:程序猿,转转请注明出处:https://www.chuangxiangniao.com/p/1353677.html

赞 (0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
Nacos实例数不稳定问题:如何解决Tornado框架下V2 API注册服务导致的实例数波动?
上一篇 2025年12月13日 17:54:13
Python Tornado注册Nacos服务,健康实例数不稳定怎么办
下一篇 2025年12月13日 17:54:19

相关推荐

发表回复

登录后才能评论
关注微信