multi front process
This commit is contained in:
@@ -278,7 +278,7 @@ void rocketmq_producer_send(rocketmq::RocketMQProducer* producer,
|
||||
producer->sendMessage(body, topic, tags, keys);
|
||||
} catch (const std::exception& e) {
|
||||
std::cerr << "[rocketmq_producer_send] 发送失败: " << e.what() << std::endl;
|
||||
DIY_ERRORLOG("process", "【ERROR】前置的%s%d号进程 MQ发送失败", get_front_msg_from_subdir(), g_front_seg_index);
|
||||
DIY_ERRORLOG("process", "【ERROR】前置的%d号进程 MQ发送失败", g_front_seg_index);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -540,7 +540,7 @@ bool parseJsonMessageSET(const std::string& json_str) {
|
||||
|
||||
std::cout << "msg index: " << index_value << " self index: " << g_front_seg_index << std::endl;
|
||||
|
||||
DIY_INFOLOG("process", "【NORMAL】前置的%s%d号进程处理topic:%s_%s的进程控制消息",get_front_msg_from_subdir(), g_front_seg_index,FRONT_INST.c_str(), G_MQCONSUMER_TOPIC_SET.c_str());
|
||||
DIY_INFOLOG("process", "【NORMAL】前置的%d号进程处理topic:%s_%s的进程控制消息", g_front_seg_index,FRONT_INST.c_str(), G_MQCONSUMER_TOPIC_SET.c_str());
|
||||
|
||||
if (code_str == "set_process") {
|
||||
if (!messageBody.contains("processNum")) {
|
||||
@@ -559,13 +559,14 @@ bool parseJsonMessageSET(const std::string& json_str) {
|
||||
// 校验参数并执行
|
||||
if ((fun == "reset" || fun == "add") &&
|
||||
(processNum >= 1 && processNum < 10) &&
|
||||
(frontType == "stat" || frontType == "recall" || frontType == "all")) {
|
||||
(frontType == "cloudfront" || frontType == "all")) {
|
||||
|
||||
if (g_node_id == STAT_DATA_BASE_NODE_ID && g_front_seg_index == 1) {
|
||||
//if (g_node_id == STAT_DATA_BASE_NODE_ID && g_front_seg_index == 1) {
|
||||
if (g_front_seg_index == 1) {
|
||||
|
||||
execute_bash(fun, processNum, frontType);
|
||||
|
||||
DIY_WARNLOG("process", "【WARN】前置的%s%d号进程执行指令:%s,reset表示重启所有进程,add表示添加进程",get_front_msg_from_subdir(), g_front_seg_index, fun.c_str());
|
||||
DIY_WARNLOG("process", "【WARN】前置的%d号进程执行指令:%s,reset表示重启所有进程,add表示添加进程", g_front_seg_index, fun.c_str());
|
||||
|
||||
send_reply_to_queue(guid, "1", "收到重置进程指令,重启所有进程!");
|
||||
std::cout << "this msg should only execute once" << std::endl;
|
||||
@@ -577,7 +578,7 @@ bool parseJsonMessageSET(const std::string& json_str) {
|
||||
|
||||
send_reply_to_queue(guid, "1", "收到删除进程指令,这个进程将会重启 ");
|
||||
|
||||
DIY_WARNLOG("process", "【WARN】前置的%s%d号进程执行指令:%s,即将重启",get_front_msg_from_subdir(), g_front_seg_index, fun.c_str());
|
||||
DIY_WARNLOG("process", "【WARN】前置的%d号进程执行指令:%s,即将重启", g_front_seg_index, fun.c_str());
|
||||
|
||||
std::this_thread::sleep_for(std::chrono::seconds(10));
|
||||
::_exit(-1039); // 进程退出
|
||||
@@ -658,15 +659,15 @@ bool parseJsonMessageLOG(const std::string& json_str) {
|
||||
}
|
||||
|
||||
// 判断 frontType 是否匹配
|
||||
if (frontType != subdir) {
|
||||
/*if (frontType != subdir) {
|
||||
std::cout << "msg frontType: " << frontType << " doesn't match self frontType: " << subdir << std::endl;
|
||||
return true;
|
||||
}
|
||||
}*/
|
||||
|
||||
DIY_INFOLOG("process", "【NORMAL】前置的%s%d号进程处理日志上送消息", get_front_msg_from_subdir(), g_front_seg_index);
|
||||
DIY_INFOLOG("process", "【NORMAL】前置的%d号进程处理日志上送消息", g_front_seg_index);
|
||||
|
||||
std::cout << "msg index: " << processNo << " self index: " << g_front_seg_index << std::endl;
|
||||
std::cout << "msg frontType: " << frontType << " self frontType: " << subdir << std::endl;
|
||||
/*std::cout << "msg frontType: " << frontType << " self frontType: " << subdir << std::endl;*/
|
||||
|
||||
// 回复消息
|
||||
send_reply_to_queue(guid, "1", "收到实时日志指令");
|
||||
@@ -683,7 +684,7 @@ bool parseJsonMessageLOG(const std::string& json_str) {
|
||||
process_log_command(id, level, grade, logtype);
|
||||
} else {
|
||||
std::cout << "type doesn't match" << std::endl;
|
||||
DIY_WARNLOG("process", "【WARN】前置的%s%d号进程处理日志上送消息,格式不正确", get_front_msg_from_subdir(), g_front_seg_index);
|
||||
DIY_WARNLOG("process", "【WARN】前置的%d号进程处理日志上送消息,格式不正确", g_front_seg_index);
|
||||
}
|
||||
|
||||
std::cout << "this msg should only execute once" << std::endl;
|
||||
@@ -737,8 +738,8 @@ bool parseJsonMessageUD(const std::string& json_str, const std::string& output_d
|
||||
|
||||
std::cout << "msg index: " << process_No << " self index: " << g_front_seg_index << std::endl;
|
||||
|
||||
DIY_INFOLOG("process", "【NORMAL】前置的%s%d号进程处理topic:%s_%s的台账更新消息",
|
||||
get_front_msg_from_subdir(), g_front_seg_index, FRONT_INST.c_str(), G_MQCONSUMER_TOPIC_UD.c_str());
|
||||
DIY_INFOLOG("process", "【NORMAL】前置的%d号进程处理topic:%s_%s的台账更新消息",
|
||||
g_front_seg_index, FRONT_INST.c_str(), G_MQCONSUMER_TOPIC_UD.c_str());
|
||||
|
||||
send_reply_to_queue(guid, "1", "收到台账更新指令");
|
||||
|
||||
@@ -865,7 +866,7 @@ rocketmq::ConsumeStatus myMessageCallbackrtdata(const rocketmq::MQMessageExt& ms
|
||||
}
|
||||
else{
|
||||
std::cerr << "rtdata is NULL." << std::endl;
|
||||
DIY_ERRORLOG("process","【ERROR】前置的%s%d号进程处理topic:%s_%s的补招触发消息失败,消息的json结构不正确",get_front_msg_from_subdir(), g_front_seg_index,FRONT_INST.c_str(), G_MQCONSUMER_TOPIC_RT.c_str());
|
||||
DIY_ERRORLOG("process","【ERROR】前置的%d号进程处理topic:%s_%s的补招触发消息失败,消息的json结构不正确", g_front_seg_index,FRONT_INST.c_str(), G_MQCONSUMER_TOPIC_RT.c_str());
|
||||
}
|
||||
|
||||
|
||||
@@ -909,7 +910,7 @@ rocketmq::ConsumeStatus myMessageCallbackupdate(const rocketmq::MQMessageExt& ms
|
||||
// 调用业务逻辑处理函数
|
||||
std::string updatefilepath = FRONT_PATH + "/etc/ledgerupdate";
|
||||
if (!parseJsonMessageUD(body, updatefilepath)) {
|
||||
DIY_ERRORLOG("process","【ERROR】前置的%s%d号进程处理topic:%s_%s的台账更新消息失败,消息的json结构不正确",get_front_msg_from_subdir(), g_front_seg_index,FRONT_INST.c_str(), G_MQCONSUMER_TOPIC_UD.c_str());
|
||||
DIY_ERRORLOG("process","【ERROR】前置的%d号进程处理topic:%s_%s的台账更新消息失败,消息的json结构不正确", g_front_seg_index,FRONT_INST.c_str(), G_MQCONSUMER_TOPIC_UD.c_str());
|
||||
}
|
||||
|
||||
return rocketmq::CONSUME_SUCCESS;
|
||||
@@ -939,7 +940,7 @@ rocketmq::ConsumeStatus myMessageCallbackset(const rocketmq::MQMessageExt& msg)
|
||||
|
||||
// 调用业务处理逻辑
|
||||
if (!parseJsonMessageSET(body)) {
|
||||
DIY_ERRORLOG("process","【ERROR】前置的%s%d号进程处理topic:%s_%s的进程控制消息失败,消息的json结构不正确",get_front_msg_from_subdir(), g_front_seg_index,FRONT_INST.c_str(), G_MQCONSUMER_TOPIC_SET.c_str());
|
||||
DIY_ERRORLOG("process","【ERROR】前置的%d号进程处理topic:%s_%s的进程控制消息失败,消息的json结构不正确", g_front_seg_index,FRONT_INST.c_str(), G_MQCONSUMER_TOPIC_SET.c_str());
|
||||
}
|
||||
|
||||
return rocketmq::CONSUME_SUCCESS;
|
||||
@@ -969,7 +970,7 @@ rocketmq::ConsumeStatus myMessageCallbacklog(const rocketmq::MQMessageExt& msg)
|
||||
|
||||
// 执行日志上送处理
|
||||
if (!parseJsonMessageLOG(body)) {
|
||||
DIY_ERRORLOG("process", "【ERROR】前置的%s%d号进程处理topic:%s_%s的日志上送消息失败,消息的json结构不正确",get_front_msg_from_subdir(), g_front_seg_index,FRONT_INST.c_str(), G_MQCONSUMER_TOPIC_LOG.c_str());
|
||||
DIY_ERRORLOG("process", "【ERROR】前置的%d号进程处理topic:%s_%s的日志上送消息失败,消息的json结构不正确", g_front_seg_index,FRONT_INST.c_str(), G_MQCONSUMER_TOPIC_LOG.c_str());
|
||||
}
|
||||
|
||||
return rocketmq::CONSUME_SUCCESS;
|
||||
@@ -1012,7 +1013,7 @@ rocketmq::ConsumeStatus myMessageCallbackrecall(const rocketmq::MQMessageExt& ms
|
||||
|
||||
} else {
|
||||
std::cerr << "recall data is NULL." << std::endl;
|
||||
DIY_ERRORLOG("process","【ERROR】前置的%s%d号进程处理topic:%s_%s的补招触发消息失败,消息的json结构不正确",get_front_msg_from_subdir(), g_front_seg_index,FRONT_INST.c_str(), G_MQCONSUMER_TOPIC_RC.c_str());
|
||||
DIY_ERRORLOG("process","【ERROR】前置的%d号进程处理topic:%s_%s的补招触发消息失败,消息的json结构不正确", g_front_seg_index,FRONT_INST.c_str(), G_MQCONSUMER_TOPIC_RC.c_str());
|
||||
}
|
||||
|
||||
return rocketmq::CONSUME_SUCCESS;
|
||||
@@ -1317,10 +1318,10 @@ void connect_status_to_queue(const std::string& id, const std::string& datetime,
|
||||
data.strTopic = G_CONNECT_TOPIC;
|
||||
data.strText = jsonObject.dump(); // 转换为字符串
|
||||
|
||||
if (g_node_id == STAT_DATA_BASE_NODE_ID) {
|
||||
std::lock_guard<std::mutex> lock(queue_data_list_mutex);
|
||||
queue_data_list.push_back(data);
|
||||
}
|
||||
//if (g_node_id == STAT_DATA_BASE_NODE_ID) {
|
||||
std::lock_guard<std::mutex> lock(queue_data_list_mutex);
|
||||
queue_data_list.push_back(data);
|
||||
//}
|
||||
}
|
||||
catch (const std::exception& e) {
|
||||
std::cerr << "connect_status_to_queue exception: " << e.what() << std::endl;
|
||||
@@ -1337,7 +1338,7 @@ void send_reply_to_queue(const std::string& guid, const std::string& step, const
|
||||
obj["step"] = step;
|
||||
obj["result"] = result;
|
||||
obj["processNo"] = g_front_seg_index;
|
||||
obj["frontType"] = get_front_type_from_subdir();
|
||||
obj["frontType"] = "cloudfront";
|
||||
obj["nodeId"] = FRONT_INST;
|
||||
|
||||
// 构造 queue 消息
|
||||
@@ -1360,7 +1361,7 @@ void send_heartbeat_to_queue(const std::string& status) {
|
||||
try{
|
||||
nlohmann::json obj;
|
||||
obj["nodeId"] = FRONT_INST;
|
||||
obj["frontType"] = get_front_type_from_subdir();
|
||||
obj["frontType"] = "cloudfront";
|
||||
obj["processNo"] = g_front_seg_index;
|
||||
obj["status"] = status;
|
||||
|
||||
@@ -1432,8 +1433,8 @@ void rocketmq_test_300(int mpnum, int front_index, int type, Front* front) {
|
||||
|
||||
if (type == 0) {
|
||||
std::cout << "use ledger send msg" << std::endl;
|
||||
|
||||
for (size_t i = 0; (total_messages > 0 && g_front_seg_index == 1 && g_node_id == 100) && i < terminal_devlist.size(); ++i) {
|
||||
//根据台账模式下每个进程都会发送
|
||||
for (size_t i = 0; total_messages > 0 && i < terminal_devlist.size(); ++i) {
|
||||
const auto& dev = terminal_devlist[i];
|
||||
|
||||
if (shouldSkipTerminal(dev.terminal_id)) {
|
||||
@@ -1478,8 +1479,8 @@ void rocketmq_test_300(int mpnum, int front_index, int type, Front* front) {
|
||||
}
|
||||
} else {
|
||||
std::cout << "use monitor + number send msg" << std::endl;
|
||||
|
||||
for (int i = 0; (total_messages > 0 && g_front_seg_index == 1 && g_node_id == 100) && i < total_messages; ++i) {
|
||||
//根据虚构监测点模式下只有进程1发送
|
||||
for (int i = 0; (total_messages > 0 && g_front_seg_index == 1 ) && i < total_messages; ++i) {
|
||||
std::string monitor_id = "testmonitor" + std::to_string(i);
|
||||
data.mp_id = monitor_id;
|
||||
data.monitor_no = i;
|
||||
|
||||
Reference in New Issue
Block a user