一个简单的应用层eventbus lib,支持redis/mqtt/rabbitmq。
pbus的Python项目详细描述
pbus系统
一个简单的应用层事件总线库,支持redis/mqtt/rabbitmq。在
安装
pip install pbus
使用
- Use with Redis/MQTT/RabbitMQ Bus class.
认购人
^{pr2}$发布
importpbusbus=pbus.RedisBus(host='127.0.0.1')# orbus=pbus.MQTTBus(host='127.0.0.1')# orbus=pbus.RabbitMQBus(host='127.0.0.1')bus.publish('test','Hello')bus=pbus.MemoryBus(exchange='ex1')bus.publish('test','Hello')
- Use with URI(recommend)
importpbusbus=pbus.connect("redis://:password@127.0.0.1:6379/2")# with db 2# orbus=pbus.connect("mqtt://username:password@127.0.0.1:1883")## or bus=pbus.connect("amqp://username:password@127.0.0.1:5672/myexchange")# with "myexchange" exchange# orbus=pbus.connect("memory:/ex1")# with "test" exchange# ...... other code
- Test event-bus speed.
- a、 运行消费者客户端
python -m pbus -u redis://127.0.0.1
- b、 运行生产者客户端
python -m pbus -u redis://127.0.0.1 -p
您将看到:
connecting to bus redis://127.0.0.1 ...
connecte success!
subscribing to pbus ...
subscribe success!
waiting data from pbus
1 : count 27748 time: 5000ms speed: 5549/s total 27748
2 : count 83135 time: 5000ms speed: 16627/s total 110883
3 : count 86416 time: 5000ms speed: 17283/s total 197299
4 : count 72546 time: 5000ms speed: 14509/s total 269845
Ctrl+C停止测试。在
- c、 同时经营消费者和生产者
python -m pbus -u redis://127.0.0.1 -l
您将看到:
Consumer: connecting to bus redis://127.0.0.1 ...
Consumer: connecte success!
Consumer: subscribing to pbus ...
Consumer: subscribe success!
Consumer: waiting data from pbus
Producer: connecting to bus redis://127.0.0.1 ...
Producer: connecte success!
Producer: will publish "Hello World!" to pbus
--Press Ctrl+C to stop it!--
Consumer: 1 : count 29119 time: 5000ms speed: 5823/s total 29119
Producer: 1 : count 29642 time: 5000ms speed: 5928/s total 29642
Click to view more information!
变更
1.0.0款
- 第一版
1.1.0款
- 支持MQTT和RabbitMQ
- 支持使用URI连接
1.2.0款
- 支持存储器
- 项目
标签: