vimacs's personal siteWritten with Vim and Emacs

fishroom消息处理过程

为了搞清tuna/fishroom是怎么转发消息的,我看了一下它的消息处理过程。

fishroom主程序

主程序为fishroom.py. fishroom主程序定义两个消息总线。

redis_client = get_redis()
msgs_from_im = MessageBus(redis_client, MsgDirection.im2fish)
msgs_to_im = MessageBus(redis_client, MsgDirection.fish2im)

fishroom不断从msgs_from_im中获取消息,检查binding看获取的消息是否是发往fishroom要处理的房间的。对于过长的消息,则会将上传到text_store,并将它的地址存放至msg.opt['text_url'].

最后这条消息会发往msgs_to_im消息总线。

IM转发

每个IM对应一个Python程序,它们也都使用两个消息总线,同时开两个线程分别操作两个总线。

在处理来自fishroom的消息时,会使用forward_msg_from_fishroom这个过程,它在base.py中定义。