Git Product home page Git Product logo

nacos-sdk-python's Introduction

nacos-sdk-python

A Python implementation of Nacos OpenAPI.

see: https://nacos.io/zh-cn/docs/open-API.html

Pypi Version License

Supported Python version:

Python 2.7 Python 3.6 Python 3.7

Supported Nacos version

Nacos 0.8.0 ~ 1.3.2

Installation

pip install nacos-sdk-python

Getting Started

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 = "server addresses split by comma"
NAMESPACE = "namespace id"

# no auth mode
client = nacos.NacosClient(SERVER_ADDRESSES, namespace=NAMESPACE)
# auth mode
#client = nacos.NacosClient(SERVER_ADDRESSES, namespace=NAMESPACE, ak="{ak}", sk="{sk}")

# get config
data_id = "config.nacos"
group = "group"
print(client.get_config(data_id, group))

Configuration

client = NacosClient(server_addresses, namespace=your_ns, ak=your_ak, sk=your_sk)
  • server_addresses - required - Nacos server address, comma separated if more than 1.
  • namespace - Namespace. | default: None
  • ak - The accessKey to authenticate. | default: null
  • sk - The secretKey to authentication. | default: null

Extra Options

Extra option can be set by set_options, as following:

client.set_options({key}={value})
# client.set_options(proxies={"http":"192.168.3.50:809"})

Configurable options are:

  • default_timeout - Default timeout for get config from server in seconds.
  • pulling_timeout - Long polling timeout in seconds.
  • pulling_config_size - Max config items number listened by one polling process.
  • callback_thread_num - Concurrency for invoking callback.
  • failover_base - Dir to store failover config files.
  • snapshot_base - Dir to store snapshot config files.
  • no_snapshot - To disable default snapshot behavior, this can be overridden by param no_snapshot in get method.
  • proxies - Dict proxy mapping, some environments require proxy access, so you can set this parameter, this way http requests go through the proxy.

API Reference

Get Config

NacosClient.get_config(data_id, group, timeout, no_snapshot)

  • param data_id Data id.

  • param group Group, use DEFAULT_GROUP if no group specified.

  • param timeout Timeout for requesting server in seconds.

  • param no_snapshot Whether to use local snapshot while server is unavailable.

  • return W Get value of one config item following priority:

  • Step 1 - Get from local failover dir(default: ${cwd}/nacos-data/data).

    • Failover dir can be manually copied from snapshot dir(default: ${cwd}/nacos-data/snapshot) in advance.
    • This helps to suppress the effect of known server failure.
  • Step 2 - Get from one server until value is got or all servers tried.

    • Content will be save to snapshot dir after got from server.
  • Step 3 - Get from snapshot dir.

Add Watchers

NacosClient.add_config_watchers(data_id, group, cb_list)

  • param data_id Data id.
  • param group Group, use DEFAULT_GROUP if no group specified.
  • param cb_list List of callback functions to add.
  • return

Add watchers to a specified config item.

  • Once changes or deletion of the item happened, callback functions will be invoked.
  • If the item is already exists in server, callback functions will be invoked for once.
  • Multiple callbacks on one item is allowed and all callback functions are invoked concurrently by threading.Thread.
  • Callback functions are invoked from current process.

Remove Watcher

NacosClient.remove_config_watcher(data_id, group, cb, remove_all)

  • param data_id Data id.
  • param group Group, use "DEFAULT_GROUP" if no group specified.
  • param cb Callback function to delete.
  • param remove_all Whether to remove all occurrence of the callback or just once.
  • return

Remove watcher from specified key.

Publish Config

NacosClient.publish_config(data_id, group, content, timeout)

  • param data_id Data id.
  • param group Group, use "DEFAULT_GROUP" if no group specified.
  • param content Config value.
  • param timeout Timeout for requesting server in seconds.
  • return True if success or an exception will be raised.

Publish one data item to Nacos.

  • If the data key is not exist, create one first.
  • If the data key is exist, update to the content specified.
  • Content can not be set to None, if there is need to delete config item, use function remove instead.

Remove Config

NacosClient.remove_config(data_id, group, timeout)

  • param data_id Data id.
  • param group Group, use "DEFAULT_GROUP" if no group specified.
  • param timeout Timeout for requesting server in seconds.
  • return True if success or an exception will be raised.

Remove one data item from Nacos.

Register Instance

NacosClient.add_naming_instance(service_name, ip, port, cluster_name, weight, metadata, enable, healthy)

  • param service_name required Service name to register to.
  • param ip required IP of the instance.
  • param port required Port of the instance.
  • param cluster_name Cluster to register to.
  • param weight A float number for load balancing weight.
  • param metadata Extra info in JSON string format or dict format
  • param enable A bool value to determine whether instance is enabled or not.
  • param healthy A bool value to determine whether instance is healthy or not.
  • param ephemeral A bool value to determine whether instance is ephemeral or not.
  • return True if success or an exception will be raised.

Deregister Instance

NacosClient.remove_naming_instance(service_name, ip, port, cluster_name)

  • param service_name required Service name to deregister from.
  • param ip required IP of the instance.
  • param port required Port of the instance.
  • param cluster_name Cluster to deregister from.
  • param ephemeral A bool value to determine whether instance is ephemeral or not.
  • return True if success or an exception will be raised.

Modify Instance

NacosClient.modify_naming_instance(service_name, ip, port, cluster_name, weight, metadata, enable)

  • param service_name required Service name.
  • param ip required IP of the instance.
  • param port required Port of the instance.
  • param cluster_name Cluster name.
  • param weight A float number for load balancing weight.
  • param metadata Extra info in JSON string format or dict format.
  • param enable A bool value to determine whether instance is enabled or not.
  • param ephemeral A bool value to determine whether instance is ephemeral or not.
  • return True if success or an exception will be raised.

Query Instances

NacosClient.list_naming_instance(service_name, clusters, namespace_id, group_name, healthy_only)

  • param service_name required Service name to query.
  • param clusters Cluster names separated by comma.
  • param namespace_id Customized group name, default blank.
  • param group_name Customized group name , default DEFAULT_GROUP.
  • param healthy_only A bool value for querying healthy instances or not.
  • return Instance info list if success or an exception will be raised.

Query Instance Detail

NacosClient.get_naming_instance(service_name, ip, port, cluster_name)

  • param service_name required Service name.
  • param ip required IP of the instance.
  • param port required Port of the instance.
  • param cluster_name Cluster name.
  • return Instance info if success or an exception will be raised.

Send Instance Beat

NacosClient.send_heartbeat(service_name, ip, port, cluster_name, weight, metadata)

  • param service_name required Service name.
  • param ip required IP of the instance.
  • param port required Port of the instance.
  • param cluster_name Cluster to register to.
  • param weight A float number for load balancing weight.
  • param ephemeral A bool value to determine whether instance is ephemeral or not.
  • param metadata Extra info in JSON string format or dict format.
  • return A JSON object include server recommended beat interval if success or an exception will be raised.

Subscribe Service Instances Changed

NacosClient.subscribe(listener_fn, listener_interval=7, *args, **kwargs)

  • param listener_fn required Customized listener function.
  • param listener_interval Listen interval , default 7 second.
  • param service_name required Service name which subscribes.
  • param clusters Cluster names separated by comma.
  • param namespace_id Customized group name, default blank.
  • param group_name Customized group name , default DEFAULT_GROUP.
  • param healthy_only A bool value for querying healthy instances or not.
  • return

Unsubscribe Service Instances Changed

NacosClient.unsubscribe(service_name, listener_name)

  • param service_name required Service name to subscribed.
  • param listener_name listener_name which is customized.
  • return

Stop All Service Subscribe

NacosClient.stop_subscribe()

  • return

Debugging Mode

Debugging mode if useful for getting more detailed log on console.

Debugging mode can be set by:

NacosClient.set_debugging()
# only effective within the current process

nacos-sdk-python's People

Contributors

mengibin avatar pixystone avatar realjacksun avatar samandqq avatar shiyiyue1102 avatar x-7 avatar xarrow avatar yanlinly avatar zhouwenb avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

nacos-sdk-python's Issues

[Enhancement] New features develop plan in version 0.1.3

New features develop plan in version 0.1.3

  1. Add a new function to the subscribe service when it changed.
    For example, this function can subscribe to the service of nacos.test , and the listener can launch an event to sense the change when service in nacos server has changed.
    Recommend method sign as nacos.client.NacosClient.subscribe(service_name:str,listeners:List[EventListener], group_name:str=None) or nacos.client.NacosClient.subscribe(service_name:str,listener:EventListener, group_name:str=None).

  2. Add a new function to the unsubscribe service.
    For example, the client can unsubscribe service positively which has subscribed.
    Recommend method sign as nacos.client.NacosClient.unsubscribe(service_name:str,listener:EventListener group_name:str=None,clusters:List[str]=None).

  3. Add a new function to trigger heartbeat schedular and keep instance always be healthy in nacos server.

如何禁用nacos日志输出

nacos日志等级会影响scrapy框架的日志等级设置,请问如何禁用掉nacos的日志输出,或者如何解决这个问题?

TypeError: __init__() got an unexpected keyword argument 'username'

编译安装的 python3.6.8,pip3 21.0.1

Traceback (most recent call last):
File "run.py", line 47, in
client = nacos.NacosClient(SERVER_ADDRESSES, namespace=NAMESPACE,username=USER,password=PASS)
TypeError: init() got an unexpected keyword argument 'username'

#部分代码如下:
import requests
import nacos

SERVER_ADDRESSES = "nacos-hello.nacos-demo.com:80
NAMESPACE="test"
data_id = "conf-tab.md"
group = "test"

USER=nacos
PASS=nacos

no auth mode

client = nacos.NacosClient(SERVER_ADDRESSES, namespace=NAMESPACE,username=USER,password=PASS)

auth mode

#client = nacos.NacosClient(SERVER_ADDRESSES, namespace=NAMESPACE, username="nacos", password="nacos")

flask项目注册到nacos,一开始没问题.过一会nacos监控那里实例数就没了

code

import datetime
import logging
import random

from flask import Flask

from pyctuator.pyctuator import Pyctuator
import nacos
# Keep the console clear - configure werkzeug (flask's WSGI web app) not to log the detail of every incoming request
logging.getLogger("werkzeug").setLevel(logging.WARNING)

my_logger = logging.getLogger("example")

app = Flask("Flask Example Server")


@app.route("/")
def hello():
    my_logger.debug(f"{datetime.datetime.now()} - {str(random.randint(0, 100))}")
    print("Printing to STDOUT")
    return "Hello World!"


example_app_address = "192.168.1.2"
example_sba_address = "192.168.1.6"

Pyctuator(
    app,
    "huiche-ai",
    app_url=f"http://{example_app_address}:5000",
    pyctuator_endpoint_url=f"http://{example_app_address}:5000/pyctuator",
    registration_url=f"http://{example_sba_address}:8764/instances",
    app_description="Demonstrate Spring Boot Admin Integration with Flask",
)
def regis_server_to_nacos():
    SERVER_ADDRESSES = "192.168.1.6"
    NAMESPACE = "public"

    # no auth mode
    client = nacos.NacosClient(SERVER_ADDRESSES, namespace=NAMESPACE)
    # auth mode
    # client = nacos.NacosClient(SERVER_ADDRESSES, namespace=NAMESPACE, username="nacos", password="nacos")

    # get config
    data_id = "nacos.cfg.dataId"
    group = "test"
    print(client.get_config(data_id, group))

    client.add_naming_instance("heiche-ai", "192.168.1.2", "5000")
if __name__ == '__main__':
    regis_server_to_nacos()
    app.run(port=5000, host="0.0.0.0",debug=True)
  1. 启动项目,nacos上成功注册
    image

2.过一会
image

没有登录模块

没有登录模块,不是使用默认账号的话,接口调用有问题

get_configs 在命名空间为public时拿不到数据问题

/nacos/v1/cs/configs?dataId=&group=&search=accurate&pageNo=1&pageSize=1000&tenant=public&username=nacos&password=nacos
这个接口在命名空间为public时,拿不到数据
初步判断,在官方提供的管理界面上,如果为public时tenant参数应该为空,所以如果命名空间为public时,需要做特殊处理

add_naming_instance的问题

调用add_naming_instance返回500,跟踪了一下发现如下情况。

add_naming_instance方法中,有一处对_do_sync_req的调用:

resp = self._do_sync_req("/nacos/v1/ns/instance", None, None, params, self.default_timeout, "POST")

其中第三个参数None传给了param,第四个参数params传给了data

_do_sync_req中会将params放在url中,将data放在body中。

而根据nacos的api规范,参数应该放在url中。所以上面的调用会返回错误。

我的环境:
python:3.6
nacos-sdk-python: 0.1.5

macOS big sur python3.9 使用 add_config_watcher 函数 TypeError: cannot pickle '_thread.RLock' object

if name == "main":
client.add_config_watcher(data_id, group, test_cb)
import time
time.sleep(3000)

Traceback (most recent call last):
File "/Users/lzh/micro_service/PythonStart/nacos_test/main.py", line 29, in
client.add_config_watcher(data_id, group, test_cb)
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/nacos/commons.py", line 10, in synced_func
return func(*args, **kws)
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/nacos/client.py", line 519, in add_config_watcher
self.add_config_watchers(data_id, group, [cb], content)
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/nacos/commons.py", line 10, in synced_func
return func(*args, **kws)
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/nacos/client.py", line 565, in add_config_watchers
puller.start()
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/multiprocessing/process.py", line 121, in start
self._popen = self._Popen(self)
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/multiprocessing/context.py", line 224, in _Popen
return _default_context.get_context().Process._Popen(process_obj)
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/multiprocessing/context.py", line 284, in _Popen
return Popen(process_obj)
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/multiprocessing/popen_spawn_posix.py", line 32, in init
super().init(process_obj)
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/multiprocessing/popen_fork.py", line 19, in init
self._launch(process_obj)
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/multiprocessing/popen_spawn_posix.py", line 47, in _launch
reduction.dump(process_obj, fp)
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/multiprocessing/reduction.py", line 60, in dump
ForkingPickler(file, protocol).dump(obj)
TypeError: cannot pickle '_thread.RLock' object

Process finished with exit code 1

不支持https协议.

公司的环境必须用https.而这个客户端我看代码里应该是写死http了.
目前我只能用requests模块获取配置.其他的特性都无法使用.
后续会考虑支持吗?

python注册的服务,在nacos的服务列表里能看到,但是在java里获取不到实例

python的注册代码
SERVER_ADDRESSES = "127.0.0.1:8848"
NAMESPACE = "public"
def func():
# no auth mode
client = nacos.NacosClient(SERVER_ADDRESSES, namespace=NAMESPACE)
client.send_heartbeat("python", "127.0.0.1", "5000")
print('send heartbeat')

java的获取代码
@RestController
public class TestController {

@Autowired
DiscoveryClient discoveryClient;
@Autowired
RestTemplate restTemplate;


@GetMapping("/hello")
public String sayHello() throws NacosException {

    List<ServiceInstance> list = discoveryClient.getInstances("python");
    ServiceInstance instance = list.get(0);
}

}
直接就报空指针了
java.lang.NullPointerException: null
at java.util.HashMap.putMapEntries(HashMap.java:500) ~[na:1.8.0_111]
at java.util.HashMap.putAll(HashMap.java:784) ~[na:1.8.0_111]
at com.alibaba.cloud.nacos.discovery.NacosServiceDiscovery.hostToServiceInstance(NacosServiceDiscovery.java:95) ~[spring-cloud-alibaba-nacos-discovery-2.2.0.RELEASE.jar:2.2.0.RELEASE]
这是什么原因啊?

Bug in add_naming_instance

Issue Description

Type: bug report

Describe what happened

Description: The NacosRequestException and 500 error are raised while the parameter filled in the function like "client.add_naming_instance(service_name='rpi-test',ip='11.11.11.11',port=8088)"

WARNING:root:[do-sync-req] server:121.36.31.116:8848 is not available for reason:
ERROR:root:[do-sync-req] 121.36.31.116:8848 maybe down, no server is currently available
ERROR:root:[add-naming-instance] exception All server are not available occur
Traceback (most recent call last):
File "/home/pi/.virtualenvs/nacos/lib/python3.7/site-packages/nacos/client.py", line 581, in add_naming_instance
resp = self._do_sync_req("/nacos/v1/ns/instance", None, None, params, self.default_timeout, "POST")
File "/home/pi/.virtualenvs/nacos/lib/python3.7/site-packages/nacos/client.py", line 452, in _do_sync_req
raise NacosRequestException("All server are not available")
nacos.exception.NacosRequestException: All server are not available
Traceback (most recent call last):
File "/home/pi/Downloads/nacos/nacos-client.py", line 27, in
client.add_naming_instance(service_name='rpi-test',ip='11.11.11.11',port=8088)
File "/home/pi/.virtualenvs/nacos/lib/python3.7/site-packages/nacos/client.py", line 581, in add_naming_instance
resp = self._do_sync_req("/nacos/v1/ns/instance", None, None, params, self.default_timeout, "POST")
File "/home/pi/.virtualenvs/nacos/lib/python3.7/site-packages/nacos/client.py", line 452, in _do_sync_req
raise NacosRequestException("All server are not available")
nacos.exception.NacosRequestException: All server are not available

How to reproduce it

Environment:

  1. run in raspberry pi4B
  2. run in OS like 2020-02-05-raspbian-buster-full
  3. python 3.7.3
  4. use function "client.add_naming_instance" with just three required parameters included service_name,ip,port

Anything else we need to know?

It's maybe a solution:

I found it caused by "metadata" and "cluster_name" when they are None instead of ''.
it equal the comand below.

curl -X POST 'http://127.0.0.1:8848/nacos/v1/ns/instance?ip=11.11.11.11&port=8088&serviceName=rpi-test&weight=1.0&enable=True&healthy=True&metadata=None&clusterName=None'

And, client.add_naming_instance(service_name='rpi-test',ip='11.11.11.11',port=8088,cluster_name='',metadata='') is available

there are many problems

i use 1.0.0.GA nacos and this plugin.

the first problem is that add_naming_instance will throw exception(HTTP 400),because the default value of paramter metadata is None,it make the request be 400.

now,the second problem is service will be down after some seconds

[Feature support grpc] add module naming

This is the sub-issue of [ISSUE #51]

Add module naming for the new version of Nacos Python SDK.

to-do list
The following parts need to be added:

  • naming.backups #56
  • naming.beat #57
  • naming.cache #58
  • naming.core #59
  • naming.dtos #60
  • naming.event #61
  • naming.remote #62
  • naming.utils #63
  • naming.nacos_naming_service #64

flask项目获取到参数该如何使用

print(client.get_config(data_id, group))
print("+++++++++++++++++++++++++")
print(type(client.get_config(data_id, group)))

get到的配置是str类型 在flask项目中该如何使用

python端心跳超时后,重新发送心跳包,在java端会报NullPointerException

python端服务注册成功后,大概每隔几周服务就会掉线。掉线后重新发送心跳包,java端就找不到实例了,此时nacos实例列表中可以看到实例,但是java端请求的时候就会报空指针。

naming-event.log

2021-08-13 12:15:58,605 INFO {POS} {IP-DISABLED} valid: 192.168.0.228:9000@DEFAULT@DEFAULT_GROUP@@semantic, region: unknown, msg: client timeout after 15000, last beat: 1628828139154

2021-08-13 12:16:13,664 INFO DEFAULT_GROUP@@semantic {SYNC} {IP-DEAD} cluster: DEFAULT, dead ips size: 1, content: [192.168.0.228:9000:unknown:DEFAULT_1.0_false_false_DEFAULT]

2021-08-13 12:16:13,664 INFO [IP-UPDATED] namespace: prod, service: DEFAULT_GROUP@@semantic, ips:

2021-08-13 12:18:19,154 INFO DEFAULT_GROUP@@semantic {SYNC} {IP-NEW} cluster: DEFAULT, new ips size: 1, content: [192.168.0.228:9000:unknown:DEFAULT_1.0_true_false_DEFAULT]

2021-08-13 12:18:19,155 INFO [IP-UPDATED] namespace: prod, service: DEFAULT_GROUP@@semantic, ips: 192.168.0.228:9000_true,

naming-server.log

2021-08-13 12:15:59,638 WARN protect threshold reached, return all ips, service: DEFAULT_GROUP@@semantic

2021-08-13 12:16:03,313 WARN protect threshold reached, return all ips, service: DEFAULT_GROUP@@semantic

2021-08-13 12:16:13,315 WARN protect threshold reached, return all ips, service: DEFAULT_GROUP@@semantic

2021-08-13 12:16:13,638 INFO [AUTO-DELETE-IP] service: DEFAULT_GROUP@@semantic, ip: {"instanceId":"192.168.0.228#9000#DEFAULT#DEFAULT_GROUP@@semantic","ip":"192.168.0.228","port":9000,"weight":1.0,"healthy":false,"enabled":true,"ephemeral":true,"clusterName":"DEFAULT","serviceName":"DEFAULT_GROUP@@semantic","metadata":{},"lastBeat":1628828139154,"marked":false,"app":"DEFAULT","instanceHeartBeatInterval":5000,"instanceIdGenerator":"simple","instanceHeartBeatTimeOut":15000,"ipDeleteTimeout":30000}

2021-08-13 12:16:13,664 INFO [NACOS-RAFT] datum is changed, key: com.alibaba.nacos.naming.iplist.ephemeral.prod##DEFAULT_GROUP@@semantic, value: {"instanceList":[]}

2021-08-13 12:18:19,154 WARN [CLIENT-BEAT] The instance has been removed for health mechanism, perform data compensation operations, beat: {"load":0.0,"cpu":0.0,"rt":0.0,"qps":0.0,"mem":0.0,"port":9000,"ip":"192.168.0.228","serviceName":"semantic","cluster":"DEFAULT","weight":1.0,"ephemeral":true}, serviceName: DEFAULT_GROUP@@semantic

2021-08-13 12:18:19,154 INFO [NACOS-RAFT] datum is changed, key: com.alibaba.nacos.naming.iplist.ephemeral.prod##DEFAULT_GROUP@@semantic, value: {"instanceList":[{"instanceId":"192.168.0.228#9000#DEFAULT#DEFAULT_GROUP@@semantic","ip":"192.168.0.228","port":9000,"weight":1.0,"healthy":true,"enabled":true,"ephemeral":true,"clusterName":"DEFAULT","serviceName":"DEFAULT_GROUP@@semantic","lastBeat":1628828299154,"marked":false,"instanceHeartBeatInterval":5000,"instanceIdGenerator":"simple","instanceHeartBeatTimeOut":15000,"ipDeleteTimeout":30000}]}

java端的log

2021-08-13 12:16:23.317 INFO 16115 --- [com.alibaba.nacos.client.naming.updater] com.alibaba.nacos.client.naming : removed ips(1) service: DEFAULT_GROUP@@semantic -> [{"clusterName":"DEFAULT","enabled":true,"ephemeral":true,"healthy":true,"instanceHeartBeatInterval":5000,"instanceHeartBeatTimeOut":15000,"instanceId":"192.168.0.228#9000#DEFAULT#DEFAULT_GROUP@@semantic","instanceIdGenerator":"simple","ip":"192.168.0.228","ipDeleteTimeout":30000,"metadata":{},"port":9000,"serviceName":"DEFAULT_GROUP@@semantic","weight":1.0}]
2021-08-13 12:16:23.318 INFO 16115 --- [com.alibaba.nacos.client.naming.updater] com.alibaba.nacos.client.naming : current ips:(0) service: DEFAULT_GROUP@@semantic -> []
2021-08-13 12:18:23.338 INFO 16115 --- [com.alibaba.nacos.client.naming.updater] com.alibaba.nacos.client.naming : new ips(1) service: DEFAULT_GROUP@@semantic -> [{"clusterName":"DEFAULT","enabled":true,"ephemeral":true,"healthy":true,"instanceHeartBeatInterval":5000,"instanceHeartBeatTimeOut":15000,"instanceId":"192.168.0.228#9000#DEFAULT#DEFAULT_GROUP@@semantic","instanceIdGenerator":"simple","ip":"192.168.0.228","ipDeleteTimeout":30000,"port":9000,"serviceName":"DEFAULT_GROUP@@semantic","weight":1.0}]
2021-08-13 12:18:23.339 INFO 16115 --- [com.alibaba.nacos.client.naming.updater] com.alibaba.nacos.client.naming : current ips:(1) service: DEFAULT_GROUP@@semantic -> [{"clusterName":"DEFAULT","enabled":true,"ephemeral":true,"healthy":true,"instanceHeartBeatInterval":5000,"instanceHeartBeatTimeOut":15000,"instanceId":"192.168.0.228#9000#DEFAULT#DEFAULT_GROUP@@semantic","instanceIdGenerator":"simple","ip":"192.168.0.228","ipDeleteTimeout":30000,"port":9000,"serviceName":"DEFAULT_GROUP@@semantic","weight":1.0}]
2021-08-13 12:19:25.319 ERROR 16115 --- [reactor-http-epoll-8] a.w.r.e.AbstractErrorWebExceptionHandler : [4107f492] 500 Server Error for HTTP POST "/semantic/bot/1a47a3f9a9af49f3"

java.lang.NullPointerException: null

2021-08-13 12:20:01.375 ERROR 16115 --- [reactor-http-epoll-3] a.w.r.e.AbstractErrorWebExceptionHandler : [76993041] 500 Server Error for HTTP POST "/semantic/bot/assistant"

java.lang.NullPointerException: null

2021-08-13 12:20:04.657 ERROR 16115 --- [reactor-http-epoll-6] a.w.r.e.AbstractErrorWebExceptionHandler : [99790b9a] 500 Server Error for HTTP POST "/semantic/bot/1a47a3f9a9af49f3"

java.lang.NullPointerException: null

2021-08-13 12:20:08.177 ERROR 16115 --- [reactor-http-epoll-7] a.w.r.e.AbstractErrorWebExceptionHandler : [e2caca67] 500 Server Error for HTTP POST "/semantic/bot/1a47a3f9a9af49f3"

how to resgister an instance?

I want to ask what is the process of registering an instance?
When I request this path /nacos/v1/ns/instance by post method, it will report 500 error.
Shall I need to create a service firstly on the nacos server?

集群数目为什么是2?

image

def regis_server_to_nacos():
    '''
    注册到nacos
    '''
    SERVER_ADDRESSES = "xxxx"
    NAMESPACE = "xxxx"
    # 获取到本机IP
    current_host_ip = get_current_host_ip()
    # no auth mode
    client = nacos.NacosClient(SERVER_ADDRESSES, namespace=NAMESPACE)
    group = "XXXXX"
    client.add_naming_instance("ner-service", current_host_ip, "80", group_name=group)
    def nacos_client_send_heartbeat():
        client.send_heartbeat("ner-service", current_host_ip, "80", group_name=group)
    return nacos_client_send_heartbeat

不支持域名形式访问

问题如下:
通过域名的形式在浏览器中访问正常,切可以通过client.py中的_do_sync_req函数拿到正确的url拼接参数,但是在_do_sync_req函数中有一个奇怪的操作server_info = self.get_server() if not server_info: logger.error("[do-sync-req] can not get one server.") raise NacosRequestException("Server is not available.") address, port = server_info server = ":".join([address, str(port)]) server_url = "%s://%s" % ("http", server) if python_version_bellow("3"): req = Request(url=server_url + url, data=urlencode(data).encode() if data else None, headers=all_headers) req.get_method = lambda: method else: req = Request(url=server_url + url, data=urlencode(data).encode() if data else None, headers=all_headers, method=method)
直接吧port加到了路由中然后去访问,这样对于通过域名方式访问就是把url拼接为 xxx.com:port ,这样会造成requests请求失败超时。希望可以兼容域名方式访问nacos。谢谢

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.