1 Star 0 Fork 11

星尘 / zbus-python

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
MIT
            /\\\                                                                             
            \/\\\                                                                            
             \/\\\                                           /\\\\\\\\\     /\\\  /\\\       
 /\\\\\\\\\\\ \/\\\         /\\\    /\\\  /\\\\\\\\\\        /\\\/////\\\   \//\\\/\\\       
 \///////\\\/  \/\\\\\\\\\  \/\\\   \/\\\ \/\\\//////        \/\\\\\\\\\\     \//\\\\\       
       /\\\/    \/\\\////\\\ \/\\\   \/\\\ \/\\\\\\\\\\       \/\\\//////       \//\\\       
      /\\\/      \/\\\  \/\\\ \/\\\   \/\\\ \////////\\\       \/\\\          /\\ /\\\       
     /\\\\\\\\\\\ \/\\\\\\\\\  \//\\\\\\\\\   /\\\\\\\\\\  /\\\ \/\\\         \//\\\\/       
     \///////////  \/////////    \/////////   \//////////  \///  \///           \////      

zbus-python-client

zbus strives to make Message Queue and Remote Procedure Call fast, light-weighted and easy to build your own service-oriented architecture for many different platforms. Simply put, zbus = mq + rpc.

zbus carefully designed on its protocol and components to embrace KISS(Keep It Simple and Stupid) principle, but in all it delivers power and elasticity.

  • Working as MQ, compare it to RabbitMQ, ActiveMQ.
  • Working as RPC, compare it to many more.

Start zbus, please refer to https://gitee.com/rushmore/zbus

Getting started

  • zbus.py has no dependency
  • zbus.py works for both python2.x and python3.x

API Demo

Only demos the gist of API, more configurable usage calls for your further interest.

Produce message

broker = Broker('localhost:15555') 

p = Producer(broker) 
p.declare('MyTopic') 

msg = Message()
msg.topic = 'MyTopic'
msg.body = 'hello world'

res = p.publish(msg)

Consume message

broker = Broker('localhost:15555')  

def message_handler(msg, client):
    print(msg)

c = Consumer(broker, 'MyTopic')
c.message_handler = message_handler 
c.start()

RPC client

broker = Broker('localhost:15555')

rpc = RpcInvoker(broker, 'MyRpc') 

res = rpc.invoke(method='plus', params=[1,2])
print(res)

res = rpc.plus(1,22)
print(res)

res = rpc.getString('hong')
print(res)

broker.close()

RPC service

class MyService(object):
    def getString(self, ping):
        return ping
    
    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'中文'

p = RpcProcessor()
p.add_module(MyService) #could be class or object


broker = Broker('localhost:15555') 

c = Consumer(broker, 'MyRpc')
c.connection_count = 1
c.message_handler = p #RpcProcessor is callable
c.start()
The MIT License (MIT) Copyright (c) 2017 rushmore Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

简介

zbus python client 展开 收起
Python
MIT
取消

发行版

暂无发行版

贡献者

全部

近期动态

加载更多
不能加载更多了
Python
1
https://gitee.com/xingchensoft/zbus-python.git
git@gitee.com:xingchensoft/zbus-python.git
xingchensoft
zbus-python
zbus-python
master

搜索帮助