修复与Zookeeper之间的连接断开导致无法收到节点变更消息的bug
diff --git a/dubbo/client.py b/dubbo/client.py
index 9280808..0d4197e 100644
--- a/dubbo/client.py
+++ b/dubbo/client.py
@@ -131,8 +131,12 @@
self.application_name = application_name
self.lock = threading.Lock()
- @staticmethod
- def state_listener(state):
+ def state_listener(self, state):
+ """
+ 监听应用和Zookeeper之间的连接状态
+ :param state:
+ :return:
+ """
logger.debug('Current state -> {}'.format(state))
if state == KazooState.LOST:
logger.debug('The session to register has lost.')
@@ -141,6 +145,19 @@
else:
logger.debug('Connected or disconnected to zookeeper.')
+ # 在新的线程里面进行重新订阅以防止死锁
+ t = threading.Thread(target=self.__resubscribe)
+ t.start()
+
+ def __resubscribe(self):
+ """
+ 由于与Zookeeper的连接断开,所以需要重新订阅消息
+ :return:
+ """
+ for interface in self.hosts.keys():
+ self.zk.get_children(DUBBO_ZK_PROVIDERS.format(interface), watch=self._watch_children)
+ self.zk.get_children(DUBBO_ZK_CONFIGURATORS.format(interface), watch=self._watch_configurators)
+
def get_provider_host(self, interface):
"""
从zk中可以根据接口名称获取到此接口某个provider的host
diff --git a/setup.py b/setup.py
index e4f5427..c9cd2b6 100644
--- a/setup.py
+++ b/setup.py
@@ -22,7 +22,7 @@
setup(
name='python-dubbo',
- version='0.0.4',
+ version='0.0.5',
url='https://github.com/RitterHou/python-dubbo',
author='hourui',
author_email='hourui@qianmi.com',