支持事件驱动开发,Bali 3.1.3 发布

Python 投稿 54500 0 评论

支持事件驱动开发,Bali 3.1.3 发布

这次的版本更新在原来已经支持的 HTTP、RPC 上增加了事件(event)支持。同时,软件的维护层面也增加了 CI 自动化测试的 Workflow。

Bali 3.1.3 更新内容:

1. 事件的定义 Event 基类

2. 事件的处理方法及事件处理独立使用一个进程

3. 文档全部使用 Mkdocs 迁移 

事件的定义方法(代码示例)

from bali.events import Eventclass 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

编程笔记 » 支持事件驱动开发,Bali 3.1.3 发布

赞同 (59) or 分享 (0)
游客 发表我的评论   换个身份
取消评论

表情
(0)个小伙伴在吐槽