You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@dubbo.apache.org by no...@apache.org on 2020/04/27 11:36:14 UTC

[dubbo-python2] 01/01: 修复与Zookeeper之间的连接断开导致无法收到节点变更消息的bug

This is an automated email from the ASF dual-hosted git repository.

not-in-ldap pushed a commit to tag 0.0.5
in repository https://gitbox.apache.org/repos/asf/dubbo-python2.git

commit 143618e8c4b268543a1a3b9d9e7954eedc564a16
Author: 侯锐 <ho...@qianmi.com>
AuthorDate: Mon Apr 27 19:35:27 2020 +0800

    修复与Zookeeper之间的连接断开导致无法收到节点变更消息的bug
---
 dubbo/client.py | 21 +++++++++++++++++++--
 setup.py        |  2 +-
 2 files changed, 20 insertions(+), 3 deletions(-)

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 @@ class ZkRegister(object):
         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 @@ class ZkRegister(object):
         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 @@ from setuptools import setup, find_packages
 
 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',