zbus python rpc service 启动异常
# encoding=utf8
import sys
sys.path.append("../../")
from zbus import Broker, Consumer, RpcProcessor, Protocol, Message
'''
MyService is just a simple Python object
'''
class MyService(object):
def getString(self, ping, i):
return '%s,%s' % (ping, i)
def echo(self, ping):
return ping
def save(self, user):
return 'OK'
def plus(self, a, b):
return int(a) + int(b)
def testEncoding(self):
return u'中文'
def redirect(self): # direct response Message
msg = Message()
msg.status = 302
msg.location = '/'
return msg
p = RpcProcessor()
p.add_module(MyService, 'InterfaceExample') # could be class or object
broker = Broker('172.17.5.23:15555')
ctrl = Message()
ctrl.topic = 'MyRpc'
ctrl.topic_mask = Protocol.MASK_MEMORY | Protocol.MASK_RPC
c = Consumer(broker, ctrl)
c.connection_count = 1
c.message_handler = p # RpcProcessor is callable
c.start()
代码是例子中的复制的
启动的时候报了下面的错误
发现下面代码会无限循环
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
多谢
@少帮主 已经解决
谢谢提醒:)
Python Package Index 已经更新
https://pypi.python.org/pypi?:action=display&name=zbuspy&version=0.11.0
zbus服务器升级了declare消费分组导致的,刚刚同步升级了zbus-python,请更新下
实际更新就是简单的增加了默认的消费分组
class ConsumeThread:
log = logging.getLogger(__name__)
def __init__(self, pool, msg_ctrl, message_handler=None, connection_count=1, timeout=60):
self.pool = pool
self.msg_ctrl = msg_ctrl
if isinstance(msg_ctrl, str):
msg = Message()
msg.topic = msg_ctrl
msg.consume_group = msg_ctrl
self.msg_ctrl = msg
if 'consume_group' not in self.msg_ctrl:
self.msg_ctrl.consume_group = self.msg_ctrl.topic