fix mq config and log control
This commit is contained in:
@@ -54,6 +54,7 @@ extern std::string G_MQCONSUMER_TOPIC_UD;
|
||||
extern std::string G_MQCONSUMER_TOPIC_RT;
|
||||
|
||||
extern std::string FRONT_INST;
|
||||
extern bool DEBUGOPEN;
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
@@ -417,6 +418,9 @@ public:
|
||||
// 设置 nameserver 地址
|
||||
SetProducerNameServerAddress(producer_, nameServer.c_str());
|
||||
|
||||
//lnk20260417设置数据上送消息体最大值,默认4M,调整为1M,避免过大消息导致发送失败
|
||||
SetProducerMaxMessageSize(producer_, 1024 * 1024); // 1MB
|
||||
|
||||
SetProducerSessionCredentials(producer_, G_MQCONSUMER_ACCESSKEY.c_str(),G_MQCONSUMER_SECRETKEY.c_str(), "");
|
||||
|
||||
// 启动生产者
|
||||
@@ -457,6 +461,64 @@ public:
|
||||
|
||||
// 发送消息
|
||||
void sendMessage(const char* strbody, const char* topic, const std::string& tags, const std::string& keys) {
|
||||
|
||||
if (DEBUGOPEN) {
|
||||
std::cout << "sendMessage called with topic: " << (topic ? topic : "NULL")
|
||||
<< ", tags: " << tags
|
||||
<< ", keys: " << keys
|
||||
<< std::endl;
|
||||
|
||||
if (strbody) {
|
||||
// ===== 1️⃣ 真实长度 vs strlen =====
|
||||
std::string body_str(strbody);
|
||||
|
||||
std::cout << "[MQ][LEN_CHECK]"
|
||||
<< " strlen=" << strlen(strbody)
|
||||
<< ", std::string.size=" << body_str.size()
|
||||
<< std::endl;
|
||||
|
||||
// ===== 2️⃣ 检测是否包含 \0 =====
|
||||
bool has_null = false;
|
||||
for (size_t i = 0; i < body_str.size(); i++) {
|
||||
if (body_str[i] == '\0') {
|
||||
has_null = true;
|
||||
std::cout << "[MQ][FOUND_NULL] index=" << i << std::endl;
|
||||
break;
|
||||
}
|
||||
}
|
||||
std::cout << "[MQ][HAS_NULL] " << (has_null ? "YES" : "NO") << std::endl;
|
||||
|
||||
// ===== 3️⃣ 打印头部(可读)=====
|
||||
size_t len = strlen(strbody);
|
||||
size_t n = std::min((size_t)200, len);
|
||||
|
||||
std::cout << "[MQ][BODY_HEAD] "
|
||||
<< std::string(strbody, n)
|
||||
<< std::endl;
|
||||
|
||||
std::cout << "[MQ][BODY_TAIL] "
|
||||
<< std::string(strbody + (len - n), n)
|
||||
<< std::endl;
|
||||
|
||||
// ===== 4️⃣ 十六进制打印前100字节 =====
|
||||
std::cout << "[MQ][HEX_HEAD] ";
|
||||
for (size_t i = 0; i < std::min((size_t)100, body_str.size()); i++) {
|
||||
printf("%02X ", (unsigned char)body_str[i]);
|
||||
}
|
||||
printf("\n");
|
||||
|
||||
// ===== 5️⃣ 十六进制打印尾部100字节 =====
|
||||
std::cout << "[MQ][HEX_TAIL] ";
|
||||
size_t start = (body_str.size() > 100) ? body_str.size() - 100 : 0;
|
||||
for (size_t i = start; i < body_str.size(); i++) {
|
||||
printf("%02X ", (unsigned char)body_str[i]);
|
||||
}
|
||||
printf("\n");
|
||||
} else {
|
||||
std::cout << "[MQ][ERROR] strbody is NULL" << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
CSendResult result;
|
||||
CMessage* msg = NULL;
|
||||
|
||||
@@ -481,6 +543,47 @@ public:
|
||||
RoundRobinSelector, // 队列选择器回调函数
|
||||
&queueNum // 传递给选择器的额外参数(队列数量)
|
||||
);
|
||||
/////////////////////////////////替换接口,性能较低但不影响
|
||||
/*CSendResult result;
|
||||
memset(&result, 0, sizeof(result));
|
||||
|
||||
int sendResult = SendMessageOrderly(
|
||||
producer_,
|
||||
msg,
|
||||
RoundRobinSelector,
|
||||
&queueNum,
|
||||
0, // autoRetryTimes
|
||||
&result
|
||||
);
|
||||
|
||||
std::cout << "[MQ][ORDERLY_RESULT]"
|
||||
<< " ret=" << sendResult
|
||||
<< ", sendStatus=" << (int)result.sendStatus
|
||||
<< ", msgId=" << result.msgId
|
||||
<< ", offset=" << result.offset
|
||||
<< ", topic=" << (topic ? topic : "")
|
||||
<< ", body_len=" << (strbody ? strlen(strbody) : 0)
|
||||
<< std::endl;*/
|
||||
/////////////////////////////////替换接口,性能较低但不影响
|
||||
// 发送消息:临时改成同步发送,绕过 orderly / selector,便于定位问题
|
||||
/*CSendResult result;
|
||||
memset(&result, 0, sizeof(result));
|
||||
|
||||
int sendResult = SendMessageSync(
|
||||
producer_,
|
||||
msg,
|
||||
&result
|
||||
);
|
||||
|
||||
std::cout << "[MQ][SYNC_RESULT]"
|
||||
<< " ret=" << sendResult
|
||||
<< ", sendStatus=" << (int)result.sendStatus
|
||||
<< ", msgId=" << result.msgId
|
||||
<< ", offset=" << result.offset
|
||||
<< ", topic=" << (topic ? topic : "")
|
||||
<< ", body_len=" << (strbody ? strlen(strbody) : 0)
|
||||
<< std::endl;*/
|
||||
// 发送消息:临时改成同步发送,绕过 orderly / selector,便于定位问题
|
||||
|
||||
if (sendResult == 0) { // 假设返回 0 表示成功
|
||||
std::cout << "[MQ][SEND_OK]"
|
||||
@@ -490,13 +593,17 @@ public:
|
||||
<< ", body_len=" << (strbody ? strlen(strbody) : 0)
|
||||
<< std::endl;
|
||||
} else {
|
||||
|
||||
std::cout << "[MQ][SEND_FAIL]"
|
||||
<< " ret=" << sendResult
|
||||
<< ", topic=" << (topic ? topic : "")
|
||||
<< ", tags=" << tags
|
||||
<< ", keys=" << keys
|
||||
<< ", body_len=" << (strbody ? strlen(strbody) : 0)
|
||||
<< std::endl;
|
||||
DIY_ERRORLOG_CODE("process",0,LOG_CODE_MQ,"【ERROR】前置的%s%d号进程 mq发送失败,请检查mq配置", get_front_msg_from_subdir(), g_front_seg_index);
|
||||
std::cout << "[MQ][BODY_HEAD] " << std::string(strbody, std::min((size_t)200, strlen(strbody))) << std::endl;
|
||||
std::cout << "[MQ][BODY_TAIL] " << std::string(strbody + std::max((size_t)0, strlen(strbody) - std::min((size_t)200, strlen(strbody)))) << std::endl;
|
||||
DIY_ERRORLOG_CODE("process",0,LOG_CODE_MQ,"【ERROR】前置的%s%d号进程 mq发送失败,请检查mq配置", get_front_msg_from_subdir(), g_front_seg_index);
|
||||
}
|
||||
|
||||
// 销毁消息
|
||||
|
||||
Reference in New Issue
Block a user