/* * @Author: yangzilong * @Last Modified by: yangzilong * @Date: 2021-11-24 19:05:28 * @Email: yangzilong@objecteye.com * @Description: */ #pragma once #include "../ai_platform/header.h" #ifdef POST_USE_RABBITMQ #include "json/json.h" #include #include #include #ifdef _RBMQ_ASYNC_INTERFACE #include #include #include #include #endif #include "spdlog/spdlog.h" #include "./rbmq/RabbitmqClient.hpp" namespace mq { class post_rabbitmq_reprocessing { /** * @brief * 1. move able only. * 2. thread safe class. * 3. support async api. * */ public: post_rabbitmq_reprocessing(); ~post_rabbitmq_reprocessing(); bool init(const rabbitmq_conn_params_t ¶ms); bool sync_publish(const std::string &msg); #ifdef _RBMQ_ASYNC_INTERFACE bool async_publish(const std::string &msg); #endif post_rabbitmq_reprocessing(post_rabbitmq_reprocessing &&other); post_rabbitmq_reprocessing& operator=(post_rabbitmq_reprocessing &&other); /* remove copy construct and copy assignment. */ post_rabbitmq_reprocessing(const post_rabbitmq_reprocessing &) = delete; post_rabbitmq_reprocessing& operator=(const post_rabbitmq_reprocessing &) = delete; private: #ifdef _RBMQ_ASYNC_INTERFACE void run(); std::thread run_thread_; std::atomic_bool is_run_; std::condition_variable run_cv_; std::queue message_buffer_; #endif std::mutex run_mutex_; rabbitmq_conn_params_t params_; std::shared_ptr rabbitmq_handle_; }; } #endif // #ifdef POST_USE_RABBITMQ