rabbitmq_message.cpp 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. #include "rabbitmq_message.h"
  2. Rabbitmq_message::Rabbitmq_message() {
  3. m_message_type = message::Message_type::eBase_msg;
  4. m_receive_time = std::chrono::system_clock::now();
  5. m_timeout_ms = std::chrono::milliseconds(0); //超时默认0秒
  6. m_sender = message::Communicator::eEmpty;
  7. m_receiver = message::Communicator::eEmpty;
  8. // m_message_buf = "";
  9. }
  10. Rabbitmq_message::Rabbitmq_message(const message::Base_info &base_info, std::string receive_string, int channel,
  11. int delivery_tag, std::string exchange_name, std::string routing_key) {
  12. m_message_type = (message::Message_type) (base_info.msg_type());
  13. m_receive_time = std::chrono::system_clock::now();
  14. m_timeout_ms = std::chrono::milliseconds(base_info.timeout_ms());
  15. m_sender = (message::Communicator) (base_info.sender());
  16. m_receiver = (message::Communicator) (base_info.receiver());
  17. m_message_buf = receive_string;
  18. m_channel = channel;
  19. m_delivery_tag = delivery_tag;
  20. m_exchange_name = exchange_name;
  21. m_routing_key = routing_key;
  22. }
  23. Rabbitmq_message::Rabbitmq_message(std::string receive_string, int channel, std::string exchange_name,
  24. std::string routing_key, int timeout_ms = 0) {
  25. m_timeout_ms = std::chrono::milliseconds(timeout_ms);
  26. m_message_buf = receive_string;
  27. m_channel = channel;
  28. m_exchange_name = exchange_name;
  29. m_routing_key = routing_key;
  30. }
  31. Rabbitmq_message::~Rabbitmq_message() {
  32. }
  33. bool Rabbitmq_message::is_over_time() {
  34. if (std::chrono::system_clock::now() - m_receive_time > m_timeout_ms) {
  35. return true;
  36. } else {
  37. return false;
  38. }
  39. }
  40. void
  41. Rabbitmq_message::reset(const message::Base_info &base_info, std::string receive_string, int channel, int delivery_tag,
  42. std::string exchange_name, std::string routing_key) {
  43. m_message_type = (message::Message_type) (base_info.msg_type());
  44. m_receive_time = std::chrono::system_clock::now();
  45. m_timeout_ms = std::chrono::milliseconds(base_info.timeout_ms());
  46. m_sender = (message::Communicator) (base_info.sender());
  47. m_receiver = (message::Communicator) (base_info.receiver());
  48. m_message_buf = receive_string;
  49. m_channel = channel;
  50. m_delivery_tag = delivery_tag;
  51. m_exchange_name = exchange_name;
  52. m_routing_key = routing_key;
  53. }
  54. void
  55. Rabbitmq_message::reset(std::string receive_string, int channel, std::string exchange_name, std::string routing_key,
  56. int timeout_ms = 0) {
  57. m_timeout_ms = std::chrono::milliseconds(timeout_ms);
  58. m_message_buf = receive_string;
  59. m_channel = channel;
  60. m_exchange_name = exchange_name;
  61. m_routing_key = routing_key;
  62. }
  63. message::Message_type Rabbitmq_message::get_message_type() {
  64. return m_message_type;
  65. }
  66. message::Communicator Rabbitmq_message::get_sender() {
  67. return m_sender;
  68. }
  69. message::Communicator Rabbitmq_message::get_receiver() {
  70. return m_receiver;
  71. }
  72. std::string Rabbitmq_message::get_message_buf() {
  73. return m_message_buf;
  74. }
  75. std::chrono::system_clock::time_point Rabbitmq_message::get_receive_time() {
  76. return m_receive_time;
  77. }