RabbitMQ.hpp 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. /*
  2. * Copyright (c)2019 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: 2023-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. namespace ZeroTier
  17. {
  18. struct MQConfig {
  19. const char *host;
  20. int port;
  21. const char *username;
  22. const char *password;
  23. };
  24. }
  25. #ifdef ZT_CONTROLLER_USE_LIBPQ
  26. #include "../node/Mutex.hpp"
  27. #include <amqp.h>
  28. #include <amqp_tcp_socket.h>
  29. #include <string>
  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