Skip to content

Commit 143618e

Browse files
author
侯锐
committed
修复与Zookeeper之间的连接断开导致无法收到节点变更消息的bug
1 parent cc06b56 commit 143618e

2 files changed

Lines changed: 20 additions & 3 deletions

File tree

dubbo/client.py

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,8 +131,12 @@ def __init__(self, hosts, application_name='search_platform'):
131131
self.application_name = application_name
132132
self.lock = threading.Lock()
133133

134-
@staticmethod
135-
def state_listener(state):
134+
def state_listener(self, state):
135+
"""
136+
监听应用和Zookeeper之间的连接状态
137+
:param state:
138+
:return:
139+
"""
136140
logger.debug('Current state -> {}'.format(state))
137141
if state == KazooState.LOST:
138142
logger.debug('The session to register has lost.')
@@ -141,6 +145,19 @@ def state_listener(state):
141145
else:
142146
logger.debug('Connected or disconnected to zookeeper.')
143147

148+
# 在新的线程里面进行重新订阅以防止死锁
149+
t = threading.Thread(target=self.__resubscribe)
150+
t.start()
151+
152+
def __resubscribe(self):
153+
"""
154+
由于与Zookeeper的连接断开,所以需要重新订阅消息
155+
:return:
156+
"""
157+
for interface in self.hosts.keys():
158+
self.zk.get_children(DUBBO_ZK_PROVIDERS.format(interface), watch=self._watch_children)
159+
self.zk.get_children(DUBBO_ZK_CONFIGURATORS.format(interface), watch=self._watch_configurators)
160+
144161
def get_provider_host(self, interface):
145162
"""
146163
从zk中可以根据接口名称获取到此接口某个provider的host

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222

2323
setup(
2424
name='python-dubbo',
25-
version='0.0.4',
25+
version='0.0.5',
2626
url='https://github.com/RitterHou/python-dubbo',
2727
author='hourui',
2828
author_email='hourui@qianmi.com',

0 commit comments

Comments
 (0)