rabbitmq_message.h 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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.h"
  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. {
  15. public:
  16. Rabbitmq_message();
  17. Rabbitmq_message(const message::Base_info& base_info, std::string receive_string, int channel, int delivery_tag, 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, int timeout_ms);
  19. Rabbitmq_message(const Rabbitmq_message& other)= default;
  20. Rabbitmq_message& operator =(const Rabbitmq_message& other)= default;
  21. ~Rabbitmq_message();
  22. public://API functions
  23. bool is_over_time();
  24. public://get or set member variable
  25. void reset(const message::Base_info& base_info, std::string receive_string, int channel, int delivery_tag, std::string exchange_name, std::string routing_key);
  26. void reset(std::string receive_string, int channel, std::string exchange_name, std::string routing_key, int timeout_ms);
  27. message::Message_type get_message_type();
  28. message::Communicator get_sender();
  29. message::Communicator get_receiver();
  30. std::string get_message_buf();
  31. std::chrono::system_clock::time_point get_receive_time();
  32. public://member variable
  33. message::Message_type m_message_type; //消息类型
  34. std::chrono::system_clock::time_point m_receive_time; //接收消息的时间点
  35. std::chrono::milliseconds m_timeout_ms; //超时时间, 整个软件都统一为毫秒
  36. message::Communicator m_sender; //发送者
  37. message::Communicator m_receiver; //接受者
  38. std::string m_message_buf; //消息数据
  39. //rabbitmq 接受特有, 保存channel和delivery_tag, 用来ack
  40. //rabbitmq 通用, 填写m_channel m_exchange_name m_routing_key 用来区别消息
  41. int m_channel; //接受消息来源的通道
  42. int m_delivery_tag; //接受消息的传递编号
  43. std::string m_exchange_name; //交换机名称
  44. std::string m_routing_key; //key,识别码
  45. private:
  46. };
  47. #endif //__RABBITMQ_MESSAGE_H