rabbitmq_message.h 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. //
  2. // Created by huli on 2020/6/29.
  3. //
  4. #ifndef __RABBITMQ_MESSAGE_H
  5. #define __RABBITMQ_MESSAGE_H
  6. #include "error_code/error_code.hpp"
  7. #include <time.h>
  8. #include <sys/time.h>
  9. #include <chrono>
  10. //#include <iosfwd>
  11. #include <string>
  12. #include "message/message_base.pb.h"
  13. class Rabbitmq_message {
  14. public:
  15. Rabbitmq_message();
  16. Rabbitmq_message(const message::Base_info &base_info, std::string receive_string, int channel, int delivery_tag,
  17. std::string exchange_name, std::string routing_key);
  18. Rabbitmq_message(std::string receive_string, int channel, std::string exchange_name, std::string routing_key,
  19. int timeout_ms);
  20. Rabbitmq_message(const Rabbitmq_message &other) = default;
  21. Rabbitmq_message &operator=(const Rabbitmq_message &other) = default;
  22. ~Rabbitmq_message();
  23. public://API functions
  24. bool is_over_time();
  25. public://get or set member variable
  26. void reset(const message::Base_info &base_info, std::string receive_string, int channel, int delivery_tag,
  27. std::string exchange_name, std::string routing_key);
  28. void
  29. reset(std::string receive_string, int channel, std::string exchange_name, std::string routing_key, int timeout_ms);
  30. message::Message_type get_message_type();
  31. message::Communicator get_sender();
  32. message::Communicator get_receiver();
  33. std::string get_message_buf();
  34. std::chrono::system_clock::time_point get_receive_time();
  35. public://member variable
  36. message::Message_type m_message_type; //消息类型
  37. std::chrono::system_clock::time_point m_receive_time; //接收消息的时间点
  38. std::chrono::milliseconds m_timeout_ms; //超时时间, 整个软件都统一为毫秒
  39. message::Communicator m_sender; //发送者
  40. message::Communicator m_receiver; //接受者
  41. std::string m_message_buf; //消息数据
  42. //rabbitmq 接受特有, 保存channel和delivery_tag, 用来ack
  43. //rabbitmq 通用, 填写m_channel m_exchange_name m_routing_key 用来区别消息
  44. int m_channel; //接受消息来源的通道
  45. int m_delivery_tag; //接受消息的传递编号
  46. std::string m_exchange_name; //交换机名称
  47. std::string m_routing_key; //key,识别码
  48. private:
  49. };
  50. #endif //__RABBITMQ_MESSAGE_H