fix mq
This commit is contained in:
@@ -401,6 +401,8 @@ public:
|
||||
// 设置 nameserver 地址
|
||||
SetProducerNameServerAddress(producer_, nameServer.c_str());
|
||||
|
||||
SetProducerSessionCredentials(producer_, G_MQCONSUMER_ACCESSKEY.c_str(),G_MQCONSUMER_SECRETKEY.c_str(), "");
|
||||
|
||||
// 启动生产者
|
||||
StartProducer(producer_);
|
||||
|
||||
@@ -411,6 +413,32 @@ public:
|
||||
RocketMQProducer(const RocketMQProducer&) = delete;
|
||||
RocketMQProducer& operator=(const RocketMQProducer&) = delete;
|
||||
|
||||
void printSendResult(const CSendResult& result) {
|
||||
std::cout << "SendResult:" << std::endl;
|
||||
std::cout << " Status: ";
|
||||
switch (result.sendStatus) {
|
||||
case E_SEND_OK:
|
||||
std::cout << "E_SEND_OK";
|
||||
break;
|
||||
case E_SEND_FLUSH_DISK_TIMEOUT:
|
||||
std::cout << "E_SEND_FLUSH_DISK_TIMEOUT";
|
||||
break;
|
||||
case E_SEND_FLUSH_SLAVE_TIMEOUT:
|
||||
std::cout << "E_SEND_FLUSH_SLAVE_TIMEOUT";
|
||||
break;
|
||||
case E_SEND_SLAVE_NOT_AVAILABLE:
|
||||
std::cout << "E_SEND_SLAVE_NOT_AVAILABLE";
|
||||
break;
|
||||
default:
|
||||
std::cout << "UNKNOWN(" << result.sendStatus << ")";
|
||||
break;
|
||||
}
|
||||
std::cout << std::endl;
|
||||
|
||||
std::cout << " MsgID : " << result.msgId << std::endl;
|
||||
std::cout << " Offset: " << result.offset << std::endl;
|
||||
}
|
||||
|
||||
// 发送消息
|
||||
void sendMessage(const char* strbody, const char* topic, const std::string& tags, const std::string& keys) {
|
||||
CSendResult result;
|
||||
@@ -439,12 +467,23 @@ public:
|
||||
);
|
||||
|
||||
//调试用
|
||||
/*
|
||||
/*int sendResult = SendMessageSync(
|
||||
producer_,
|
||||
msg,
|
||||
&result
|
||||
);
|
||||
int ret = SendMessageSync(producer_, msg, &result);
|
||||
if (ret == 0) {
|
||||
printSendResult(result);
|
||||
} else {
|
||||
std::cerr << "SendMessageSync failed with ret=" << ret << std::endl;
|
||||
}*/
|
||||
|
||||
if (sendResult == 0) { // 假设返回 0 表示成功
|
||||
std::cout << "Message sent successfully.topic:" << topic <<std::endl;
|
||||
} else {
|
||||
std::cout << "Failed to send message." << std::endl;
|
||||
}*/
|
||||
}
|
||||
|
||||
// 销毁消息
|
||||
DestroyMessage(msg);
|
||||
|
||||
BIN
pt61850netd_pqfe
Normal file
BIN
pt61850netd_pqfe
Normal file
Binary file not shown.
BIN
pt61850netd_pqfed
Normal file
BIN
pt61850netd_pqfed
Normal file
Binary file not shown.
Reference in New Issue
Block a user