-
Notifications
You must be signed in to change notification settings - Fork 104
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
76 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
#-*- config: utf8 -*- | ||
|
||
import nacos | ||
import json | ||
|
||
SERVER_ADDRESSES = "http://127.0.0.1:8848" | ||
NAMESPACE = "dev" | ||
|
||
client = nacos.NacosClient(SERVER_ADDRESSES, namespace=NAMESPACE) | ||
|
||
# auth mode | ||
#client = nacos.NacosClient(Server_ADDRESSES, namespace=NAMESPACE,ak="{ak}",sk="{sk}") | ||
|
||
data_id = "config.001" | ||
group = "default" | ||
|
||
def change_config_info(times): | ||
d = {"name":"foo","value":-1} | ||
for i in range(times): | ||
d["value"]=i | ||
config_str= json.dumps(d) | ||
client.publish_config(data_id,group,config_str) | ||
print("publish value:",config_str) | ||
time.sleep(1) | ||
get_value = client.get_config(data_id,group) | ||
print("get value:",get_value) | ||
|
||
def config_watcher(params): | ||
print("config_watcher change:",params) | ||
|
||
def main(): | ||
# publish config | ||
print("publish config:",client.publish_config(data_id,group,"hello info")) | ||
# get config | ||
print("get config:",client.get_config(data_id,group)) | ||
# use config watcher | ||
client.add_config_watcher(data_id,group,config_watcher) | ||
# change config value | ||
change_config_info(10) | ||
|
||
if __name__ == "__main__": | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
#-*- config: utf8 -*- | ||
|
||
import nacos | ||
from nacos.listener import SubscribeListener | ||
import time | ||
|
||
SERVER_ADDRESSES = "http://127.0.0.1:8848" | ||
NAMESPACE = "dev" | ||
|
||
client = nacos.NacosClient(SERVER_ADDRESSES, namespace=NAMESPACE) | ||
|
||
# auth mode | ||
#client = nacos.NacosClient(Server_ADDRESSES, namespace=NAMESPACE,ak="{ak}",sk="{sk}") | ||
|
||
data_id = "config.001" | ||
group = "default" | ||
service_name = "foo_service" | ||
|
||
def instance_subscribe(*args,**kv): | ||
print("instance_subscribe:",args[0],args[1].__dict__) | ||
|
||
def add_naming_instance(num): | ||
for i in range(num): | ||
client.add_naming_instance(service_name,"192.168.10.{0}".format(100+i),8080,group_name = group,heartbeat_interval=5) | ||
time.sleep(0.5) | ||
|
||
def main(): | ||
subscriber = SubscribeListener(instance_subscribe,group) | ||
client.subscribe(subscriber,service_name = service_name,group_name = group) | ||
add_naming_instance(10) | ||
print("holding") | ||
|
||
if __name__ == "__main__": | ||
main() |