| 13 | #include "../MyParams/MyMessageParam.h" |
| 14 | |
| 15 | class MyPubMessageNode : public CGraph::GNode { |
| 16 | public: |
| 17 | CStatus init() override { |
| 18 | int sleep = 300; |
| 19 | CGRAPH_SLEEP_MILLISECOND(sleep) // 休息,确保其他的sub节点,已经完成了订阅 |
| 20 | CGraph::CGRAPH_ECHO("==> [MyPubMessageNode] [init], sleep [%d] ms, to make sure sub node prepare ok.", |
| 21 | sleep); |
| 22 | return CStatus(); |
| 23 | } |
| 24 | |
| 25 | CStatus run() override { |
| 26 | std::shared_ptr<MyMessageParam> mp(new MyMessageParam()); // 创建一个消息,并且发送出去 |
| 27 | mp->num = (num_++) * 100; |
| 28 | mp->info = "this is a test info, num = " + std::to_string(mp->num); |
| 29 | CStatus status = CGRAPH_PUB_MPARAM(MyMessageParam, "pub-sub", mp, CGraph::GMessagePushStrategy::WAIT); |
| 30 | return status; |
| 31 | } |
| 32 | |
| 33 | private: |
| 34 | int num_ = 0; |
| 35 | }; |
| 36 | |
| 37 | |
| 38 | #endif //CGRAPH_MYPUBMESSAGENODE_H |
nothing calls this directly
no outgoing calls
no test coverage detected