Git Product home page Git Product logo

Comments (7)

Daydreamer-ia avatar Daydreamer-ia commented on May 26, 2024

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)

from nacos.

CZJCC avatar CZJCC commented on May 26, 2024

我也没办法复现,可以提供更多你的客户端实现代码吗

from nacos.

KunxiSun avatar KunxiSun commented on May 26, 2024

版本2.x的nacos用不了官方推荐的那个nacos_python_sdk,不兼容

from nacos.

Daydreamer-ia avatar Daydreamer-ia commented on May 26, 2024

版本2.x的nacos用不了官方推荐的那个nacos_python_sdk,不兼容

兼容的,2.x的服务端保留了1.x所有的api接口

from nacos.

KunxiSun avatar KunxiSun commented on May 26, 2024

版本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)

from nacos.

KomachiSion avatar KomachiSion commented on May 26, 2024

升级一下python-sdk版本试一下呢? 我也没法复现。

from nacos.

KomachiSion avatar KomachiSion commented on May 26, 2024

No more response from author for a long time, and this problem seems new version has solved this problem.

from nacos.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.