nacos
nacos copied to clipboard
python client heartbeat failed
Describe the bug python 客户端心跳检查报错,客户端报错日志:
nacos 服务端报错日志:
Desktop (please complete the following information):
- OS: centos7.9
- Version nacos-server 2.3.2
- Module [e.g. naming/config]
- SDK: nacos-sdk-python==0.1.14
- python version: 3.11.7
You need to register instance before you send heartbeat. I cannot reproduce it.
import nacos
# Both HTTP/HTTPS protocols are supported, if not set protocol prefix default is HTTP, and HTTPS with no ssl check(verify=False)
# "192.168.3.4:8848" or "https://192.168.3.4:443" or "http://192.168.3.4:8848,192.168.3.5:8848" or "https://192.168.3.4:443,https://192.168.3.5:443"
SERVER_ADDRESSES = "127.0.0.1"
NAMESPACE = "public"
# no auth mode
client = nacos.NacosClient(SERVER_ADDRESSES, namespace=NAMESPACE)
client.add_naming_instance("test_11", "127.0.0.1",1000)
client.send_heartbeat("test_11", "127.0.0.1", 1000)
我也没办法复现,可以提供更多你的客户端实现代码吗
版本2.x的nacos用不了官方推荐的那个nacos_python_sdk,不兼容
版本2.x的nacos用不了官方推荐的那个nacos_python_sdk,不兼容
兼容的,2.x的服务端保留了1.x所有的api接口
版本2.x的nacos用不了官方推荐的那个nacos_python_sdk,不兼容
兼容的,2.x的服务端保留了1.x所有的api接口
尝试过的:
# Not working: 这个方法发不出心跳
NacosClient.send_heartbeat(service_name, ip, port, cluster_name, weight, metadata)
心跳发不出去的,下面是我的 work around,用add_naming_instance的方法持续注册(bad idea)
class NacosManager:
def __init__(self, nacos_cfg: NacosConfig = None):
if nacos_cfg is None:
nacos_cfg = NacosConfig()
self.nacos_cfg = nacos_cfg
self.service_host: str = find_this_host() #服务注册的地址
self.service_port: int = find_free_port() #服务注册的端口
# Nacos的交互实例
self.client = NacosClient(
server_addresses = self.nacos_cfg.server_addresses,
namespace = self.nacos_cfg.namespace_id
)
def register(self) -> None:
"""
注册服务到nacos
"""
self.client.add_naming_instance(
service_name = self.nacos_cfg.service_name,
ip = self.service_host,
port = self.service_port,
cluster_name = self.nacos_cfg.service_cluster_name,
group_name = self.nacos_cfg.group_name
)
def heartbeat(self) -> None:
"""
异步发送心跳
"""
while True:
# FIXME: 发送心跳不管用,因为nacos是2.04版本,这个sdk不支持,所以改成5秒钟注册一次
self.register()
time.sleep(5)
升级一下python-sdk版本试一下呢? 我也没法复现。
No more response from author for a long time, and this problem seems new version has solved this problem.