cexchange.hpp 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. #ifndef CEXCHANGE_H
  2. #define CEXCHANGE_H
  3. #include <string>
  4. /**
  5. * @brief 交换机
  6. **/
  7. class CExchange
  8. {
  9. public:
  10. CExchange(std::string name, std::string type = "direct",
  11. bool durable = true, bool passive = false, bool auto_delete = false, bool internal = false)
  12. :m_name(name),
  13. m_type(type),
  14. m_bDurable(durable),
  15. m_bPassive(passive),
  16. m_bAutoDelete(auto_delete),
  17. m_bInternal(internal)
  18. {
  19. }
  20. CExchange(const CExchange &other)
  21. {
  22. this->m_name = other.m_name;
  23. this->m_bDurable = other.m_bDurable;
  24. this->m_type = other.m_type;
  25. this->m_bAutoDelete = other.m_bAutoDelete;
  26. this->m_bInternal = other.m_bInternal;
  27. this->m_bPassive = other.m_bPassive;
  28. }
  29. CExchange operator=(const CExchange &other)
  30. {
  31. if (this == &other)
  32. return *this;
  33. this->m_name = other.m_name;
  34. this->m_bDurable = other.m_bDurable;
  35. this->m_type = other.m_type;
  36. this->m_bAutoDelete = other.m_bAutoDelete;
  37. this->m_bInternal = other.m_bInternal;
  38. this->m_bPassive = other.m_bPassive;
  39. return *this;
  40. }
  41. /**
  42. * m_name 交换机名称
  43. *
  44. **/
  45. std::string m_name;
  46. /**
  47. * m_type 指定exchange类型,"fanout" "direct" "topic"三选一
  48. * "fanout" 广播的方式,发送到该exchange的所有队列上(不需要进行bind操作)
  49. * "direct" 通过路由键发送到指定的队列上(把消息发送到匹配routing key的队列中。)
  50. * "topic" 通过匹配路由键的方式获取,使用通配符*,#
  51. **/
  52. std::string m_type;
  53. /**
  54. * m_durable 交换机是否持久化(当mq服务端断开重启后,交换机是否还存在)
  55. **/
  56. bool m_bDurable;
  57. /**
  58. * m_auto_delete 连接断开时,交换机是否自动删除
  59. *
  60. **/
  61. bool m_bAutoDelete;
  62. /**
  63. * m_internal 默认为0,没有使用到
  64. *
  65. **/
  66. bool m_bInternal;
  67. /**
  68. * passive 检测exchange是否存在
  69. * 设为true,
  70. * 若exchange存在则命令成功返回(调用其他参数不会影响exchange属性),
  71. * 若不存在不会创建exchange,返回错误。
  72. * 设为false,
  73. * 如果exchange不存在则创建exchange,调用成功返回。
  74. * 如果exchange已经存在,并且匹配现在exchange的话则成功返回,如果不匹配则exchange声明失败。
  75. **/
  76. bool m_bPassive;
  77. };
  78. #endif // CEXCHANGE_H