Bali 3.1.3 发布,支持事件驱动开发
这次的版本更新在原来已经支持的 HTTP、RPC 上增加了事件(event)支持。同时,软件的维护层面也增加了 CI 自动化测试的 Workflow。 更新内容: 1. 事件的定义 Event 基类 2. 事件的处理方法及事件处理独立使用一个进程 3. 文档全部使用 Mkdocs 迁移 事件的定义方法(代码示例) from bali.events import Event class HelloEvent(Event): # The __amqp_name__ here defaults to default, # which means that the AMQP configuration using default is used __amqp_name__ = 'default' def dict(self, *args, **kwargs): # Rewrite dict to allow events to be transferred in the AMQP component in the way you define. # If dict is not rewritten, the message will be {'type': self.type, 'payload': self.payload} return {'type': self.type, **self.payload} 事件的 publish 方法(代码示例) dispatch(HelloEvent(type='hello', payload={'aaa':'bbb'})) 事件的 handle 方法(代码示例) class EventHandler: @event_handler('hello') def handle_event(event): print(event) 事件 handle 的进程启动 python main.py --event