RabbitMQ.hpp 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. /*
  2. * ZeroTier One - Network Virtualization Everywhere
  3. * Copyright (C) 2011-2019 ZeroTier, Inc. https://www.zerotier.com/
  4. *
  5. * This program is free software: you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation, either version 3 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. *
  18. * --
  19. *
  20. * You can be released from the requirements of the license by purchasing
  21. * a commercial license. Buying such a license is mandatory as soon as you
  22. * develop commercial closed-source software that incorporates or links
  23. * directly against ZeroTier software without disclosing the source code
  24. * of your own application.
  25. */
  26. #ifndef ZT_CONTROLLER_RABBITMQ_HPP
  27. #define ZT_CONTROLLER_RABBITMQ_HPP
  28. namespace ZeroTier
  29. {
  30. struct MQConfig {
  31. const char *host;
  32. int port;
  33. const char *username;
  34. const char *password;
  35. };
  36. }
  37. #ifdef ZT_CONTROLLER_USE_LIBPQ
  38. #include "../node/Mutex.hpp"
  39. #include <amqp.h>
  40. #include <amqp_tcp_socket.h>
  41. #include <string>
  42. namespace ZeroTier
  43. {
  44. class RabbitMQ {
  45. public:
  46. RabbitMQ(MQConfig *cfg, const char *queueName);
  47. ~RabbitMQ();
  48. void init();
  49. std::string consume();
  50. private:
  51. MQConfig *_mqc;
  52. const char *_qName;
  53. amqp_socket_t *_socket;
  54. amqp_connection_state_t _conn;
  55. amqp_queue_declare_ok_t *_q;
  56. int _status;
  57. int _channel;
  58. Mutex _chan_m;
  59. };
  60. }
  61. #endif // ZT_CONTROLLER_USE_LIBPQ
  62. #endif // ZT_CONTROLLER_RABBITMQ_HPP