去Anyblock的巴士
anyblok_bus的Python项目详细描述
AnyBlok / bus
改进AnyBlok以添加与总线的通信。
Blok | Dependancies | Description |
---|---|---|
bus | Consume and publish message with pika and marshmallow |
anyblok/bus是根据mozilla公共许可协议的条款发布的。
Usage
Declare a new consumer
在anyblok模型中,您必须用bus消费者装饰方法
from anyblok_bus import bus_consumer from anyblok import Declarations from .schema import MySchema @Declarations.register(Declarations.Model) class MyModel: @bus_consumer(queue_name='name of the queue', schema=MySchema()) def my_consumer(cls, body): # do something
架构必须是marshmallow.schema的实例,see the marshmallow documentation
注意
修饰的方法成为一个始终具有相同原型(cls,body)的classmethod body是模式对来自队列的消息进行的去序列化。
Publish a message through rabbitmq
发布由registry.bus.publish方法完成:
registry.Bus.publish('exchange', 'routing_key', message, mimestype)
如果消息尚未发送,则会引发异常
。警告:
A profile must be defined and selected by the AnyBlok configuration **bus_profile**
Front Matter
有关anyblok/bus项目的信息。
Project Homepage
anyblok托管在github-主项目上 页面位于https://github.com/AnyBlok/anyblok_bus。源代码是 在这里使用GIT跟踪。
pypi上的版本和项目状态位于 http://pypi.python.org/pypi/anyblok_bus。
此文档的最新发布版本应位于 http://doc.anyblok-bus.anyblok.org。
Installation
从python包索引安装anyblok的发布版本 pip或类似工具:
pip install anyblok_bus
通过源发行版安装是通过setup.py脚本:
python setup.py install
安装程序将向环境中添加anyblok命令。
Script
anyblok_总线添加console_script以启动工作进程。工作进程使用定义的队列 由装饰者anyblok_bus.bus_consumer提供:
anyblok_bus -c anyblok_config_file.cfg
。注意:配置中的配置文件名用于查找连接到rabbitmq的正确url
Dependencies
anyblok/bus与python>;=3.4及更高版本和pika >= 1.0.1一起工作。安装过程将 确保安装了AnyBlok以及其他 依赖关系。强烈建议使用最新版本。
CHANGELOG
1.2.0 (2019-06-24)
更新版本以使用pika>;=1.0.1
固定了同一型号上的多个消费者
重构了总线控制台脚本,在总线消费者上添加了进程参数。 目标是为一个队列定义进程,默认情况下为所有队列 处于相同的过程中
当队列丢失时添加更好的日志记录。如果缺少队列,则 工人们不会开工。
添加了适配器参数来转换总线消息,schema属性 贝康现在给适配器一个简单的kwargs参数。
不需要适配器。
注意
为了保持兼容性,如果没有用模式定义适配器,那么 适配器是模式适配器
1.1.0 (2018-09-15)
- 改进的日志记录:用于帮助调试消息
- 添加了“创建和更新日期”列
- 修复了consume_all方法。现在,当引发异常时,该方法不会停止
- 旧版Marsmallow>;=3.0.0
1.0.0 (2018-06-05)
- 添加worker以使用rabbitmq中的消息
- 添加发布方法以将消息发布到rabbitmq
- 添加anyblok_bus.bus_consumer将decorator添加到défine the consumer