Dubbo--kazoo库操作zk

kazzo库使用

from kazoo.client import KazooClient
from urllib.parse import unquote


zk_host = '10.12.224.14:2181'
server_name = 'com.bjpowernode.dubbo.service.UserService'

zk = KazooClient(hosts=zk_host, read_only=True, timeout=30.0)
zk.start()
print(zk.state)

# 获取节点
print(zk.get_children('/'))
print(zk.get_children('/dubbo'))
print(zk.get_children('/dubbo/'+server_name))

# rpc
rpc_link = zk.get_children('/dubbo/' + server_name + '/providers')
print(rpc_link)

# url解码
rpc_link = unquote("".join(rpc_link))
print(rpc_link)

# 获取ip
ip = rpc_link.split("/")[2].split(':')[0]
print(ip)

# 停止zkClient
zk.stop()

# 关闭连接
zk.close()
print(zk.state)
CONNECTED
['dubbo', 'zookeeper']
['com.bjpowernode.dubbo.service.UserService']
['consumers', 'configurators', 'routers', 'providers']
['dubbo%3A%2F%2F10.12.224.14%3A20880%2Fcom.bjpowernode.dubbo.service.UserService%3Fanyhost%3Dtrue%26application%3D007-zk-userservice-provider%26dubbo%3D2.6.2%26generic%3Dfalse%26interface%3Dcom.bjpowernode.dubbo.service.UserService%26methods%3DqueryUserById%26pid%3D44290%26revision%3D1.0.0%26side%3Dprovider%26timestamp%3D1614648799799']
dubbo://10.12.224.14:20880/com.bjpowernode.dubbo.service.UserService?anyhost=true&application=007-zk-userservice-provider&dubbo=2.6.2&generic=false&interface=com.bjpowernode.dubbo.service.UserService&methods=queryUserById&pid=44290&revision=1.0.0&side=provider&timestamp=1614648799799
10.12.224.14
LOST
上一篇:大数据学习(22)—— ZooKeeper能做些什么


下一篇:揭秘井井有条的流水线(ZooKeeper 原理篇)