/* * @Author: yangzilong * @Date: 2021-12-15 15:00:28 * @Last Modified by: yangzilong * @Email: yangzilong@objecteye.com * @Description: */ #include "./mq_manager.hpp" #include "../common/logger.hpp" #ifdef POST_USE_RABBITMQ namespace mq { Manager::Manager() { }; bool Manager::add_conn(const key_t &key, const value_param_t& value_param) { if (task_status_to_mq_handle_.find(key) != task_status_to_mq_handle_.end()) return false; std::shared_ptr value = std::make_shared(); if (!value->init(value_param)) return false; task_status_to_mq_handle_[key] = value; return true; } bool Manager::del_conn(const key_t &key) { if (task_status_to_mq_handle_.find(key) == task_status_to_mq_handle_.end()) return false; task_status_to_mq_handle_.erase(key); return true; } bool Manager::publish(const key_t &key, const char *msg, bool verbose) { if (task_status_to_mq_handle_.find(key) == task_status_to_mq_handle_.end()) return false; bool status; if (!(status = task_status_to_mq_handle_[key]->sync_publish(msg))) LOG_ERROR("rbMQ publish {} failed", msg); else if (verbose) LOG_DEBUG("rbMQ publish {} successful", msg); return status; } } #endif // #ifdef POST_USE_RABBITMQ