Omit deployment method , Baidu or Google
Nacos file
service (Service) yes Nacos First class citizens of the world .Nacos Support almost all major types of “ service ” Discovery 、 Configure and manage :
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 = "http:// Change to your own ip: port "
NAMESPACE = ""
# 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 = "python_project.json"
group = "dev"
print(client.get_config(data_id, group))
nacos_data = eval(client.get_config(data_id, group))
password = nacos_data["password"]
print("password is", password)
def test_cb(args):
print("nacos Configuration changes ")
global password
nacos_data = eval(client.get_config(data_id, group))
password = nacos_data["password"]
# Registration service
a = client.add_naming_instance("changyu_test1", "www.baidu.com", 80)
print(a)
# The discovery service
b = client.list_naming_instance("changyu_test1")
print(b)
print("ip", b["hosts"][0]["ip"])
print("port", b["hosts"][0]["port"])
if __name__ == '__main__':
# Listening for configuration changes
client.add_config_watcher(data_id, group, test_cb)
import time
time.sleep(10000)