程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式師世界 >> 編程語言 >  >> 更多編程語言 >> Python

Nacos configuration center, service registration and discovery, python version

編輯:Python

Omit deployment method , Baidu or Google

1: Nacos Introduce

Nacos file

service (Service) yes Nacos First class citizens of the world .Nacos Support almost all major types of “ service ” Discovery 、 Configure and manage :

2:python Script

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)

  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式師世界 All Rights Reserved