# message_bus **Repository Path**: DavildG/message_bus ## Basic Information - **Project Name**: message_bus - **Description**: 一个消息总线模块:当收到等待的消息时,调用回调函数;当在规定时间内没收到时,调用超时响应函数。 - **Primary Language**: C++ - **License**: MIT - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 23 - **Created**: 2023-02-21 - **Last Updated**: 2023-02-21 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README ## message_bus + 该模块一般用在客户端; + 基于消息的程序架构(如C/S架构),在发送一个request消息后可能会遇到这样的情况: + 等到response消息,其中response分为肯定回答和否定回答; + 在超时时间内没有收到回复。 业务往往需要等到响应结果以后再继续其他业务,设计方法是:采用回调的方法调用响应函数,维护一个定时器,不停检查是否有超时消息产生,并调用对应回调函数。 + 需要使用到定时器,定时器默认间隔100ms。 + 维护了一个超时消息的列表。 ## 主要结构体 ```cpp typedef std::function Callback_t; typedef std::function TimeOutCallback_t; struct CallbackItem_t { Callback_t callback = nullptr; TimeOutCallback_t timeOutCallback = nullptr; uint32_t timeoutInterval = 1000; // 超时时间,milliseconds uint64_t timeoutStamp = 0; // 内部使用时间戳,用户无需填写,microseconds std::vector msgNumVec; // 需要关注的消息号 CallbackType_t callbackType = ALWAYS; }; typedef std::shared_ptr CallbackItem_ptr; typedef std::map> CallbackMap_t; CallbackMap_t _callbackMap; // message dispatch map std::list _timeoutCheckList; // timeout check list ```