zbus python rpc service 启动异常

娄旺超 发布于 2017/11/29 11:01
阅读 247
收藏 0

如何使用英特尔®oneAPI工具实现PyTorch 优化,直播火热报名中>>>

# 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()

代码是例子中的复制的

启动的时候报了下面的错误

发现下面代码会无限循环

 

加载中
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

0
少帮主
少帮主

谢谢提醒:)

Python Package Index 已经更新

https://pypi.python.org/pypi?:action=display&name=zbuspy&version=0.11.0

 

娄旺超
娄旺超
多谢 @少帮主 已经解决
OSCHINA
登录后可查看更多优质内容
返回顶部
顶部