diff --git a/cfg_parse/SimpleProducer.cpp b/cfg_parse/SimpleProducer.cpp index 1648f45..64e4abf 100644 --- a/cfg_parse/SimpleProducer.cpp +++ b/cfg_parse/SimpleProducer.cpp @@ -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 <