RabbitMQ.hpp 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. /*
  2. * Copyright (c)2013-2020 ZeroTier, Inc.
  3. *
  4. * Use of this software is governed by the Business Source License included
  5. * in the LICENSE.TXT file in the project's root directory.
  6. *
  7. * Change Date: 2024-01-01
  8. *
  9. * On the date above, in accordance with the Business Source License, use
  10. * of this software will be governed by version 2.0 of the Apache License.
  11. */
  12. /****/
  13. #ifndef ZT_CONTROLLER_RABBITMQ_HPP
  14. #define ZT_CONTROLLER_RABBITMQ_HPP
  15. #include "DB.hpp"
  16. #include <string>
  17. namespace ZeroTier
  18. {
  19. struct MQConfig {
  20. std::string host;
  21. int port;
  22. std::string username;
  23. std::string password;
  24. };
  25. }
  26. #ifdef ZT_CONTROLLER_USE_LIBPQ
  27. #include "../core/Mutex.hpp"
  28. #include <amqp.h>
  29. #include <amqp_tcp_socket.h>
  30. namespace ZeroTier
  31. {
  32. class RabbitMQ {
  33. public:
  34. RabbitMQ(MQConfig *cfg, const char *queueName);
  35. ~RabbitMQ();
  36. void init();
  37. std::string consume();
  38. private:
  39. MQConfig *_mqc;
  40. const char *_qName;
  41. amqp_socket_t *_socket;
  42. amqp_connection_state_t _conn;
  43. amqp_queue_declare_ok_t *_q;
  44. int _status;
  45. int _channel;
  46. Mutex _chan_m;
  47. };
  48. }
  49. #endif // ZT_CONTROLLER_USE_LIBPQ
  50. #endif // ZT_CONTROLLER_RABBITMQ_HPP