This is an automated email from the ASF dual-hosted git repository. dinglei pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/rocketmq-client-cpp.git
The following commit(s) were added to refs/heads/master by this push: new 3505ecf fix: send failed show exception details (#486) 3505ecf is described below commit 3505ecf8d88d471adcb0715a68fa4a8617ed86bd Author: Humkum <1109939...@qq.com> AuthorDate: Tue Mar 4 15:00:26 2025 +0800 fix: send failed show exception details (#486) Co-authored-by: 韩坤明 <hankunm...@xiaomi.com> --- src/MQClientAPIImpl.cpp | 5 ++++- src/producer/DefaultMQProducerImpl.cpp | 26 ++++++++++++++++++++++---- 2 files changed, 26 insertions(+), 5 deletions(-) diff --git a/src/MQClientAPIImpl.cpp b/src/MQClientAPIImpl.cpp index 671f328..420a623 100644 --- a/src/MQClientAPIImpl.cpp +++ b/src/MQClientAPIImpl.cpp @@ -405,8 +405,11 @@ SendResult MQClientAPIImpl::sendMessageSync(const string& addr, LOG_DEBUG("sendMessageSync success:%s to addr:%s,brokername:%s, send status:%d", msg.toString().c_str(), addr.c_str(), brokerName.c_str(), (int)result.getSendStatus()); return result; + } catch (std::exception& e) { + LOG_ERROR("send new error, broker:%s, details:%s", brokerName.c_str(), e.what()); + throw e; } catch (...) { - LOG_ERROR("send error"); + LOG_ERROR("Unknown error, broker:%s", brokerName.c_str()); } } THROW_MQEXCEPTION(MQClientException, "response is null", -1); diff --git a/src/producer/DefaultMQProducerImpl.cpp b/src/producer/DefaultMQProducerImpl.cpp index cfa1f37..20a9dc3 100644 --- a/src/producer/DefaultMQProducerImpl.cpp +++ b/src/producer/DefaultMQProducerImpl.cpp @@ -376,6 +376,8 @@ SendResult DefaultMQProducerImpl::sendDefaultImpl(MQMessage& msg, bool bActiveMQ) { MQMessageQueue lastmq; int mq_index = 0; + bool send_failed = false; + string failed_detail; for (int times = 1; times <= m_retryTimes; times++) { boost::weak_ptr<TopicPublishInfo> weak_topicPublishInfo( getFactory()->tryToFindTopicPublishInfo(msg.getTopic(), getSessionCredentials())); @@ -420,16 +422,23 @@ SendResult DefaultMQProducerImpl::sendDefaultImpl(MQMessage& msg, default: break; } - } catch (...) { - LOG_ERROR("send failed of times:%d,brokerName:%s", times, mq.getBrokerName().c_str()); + } catch (std::exception& e) { + send_failed = true; + failed_detail = e.what(); + LOG_ERROR("send failed of times:%d,brokerName:%s,details:%s", times, mq.getBrokerName().c_str(), e.what()); if (bActiveMQ) { topicPublishInfo->updateNonServiceMessageQueue(mq, getSendMsgTimeout()); } continue; + } catch (...) { + LOG_ERROR("Unknown error, send failed of times:%d, brokerName:%s", times, mq.getBrokerName().c_str()); } } // end of for LOG_WARN("Retry many times, still failed"); } + if (send_failed) { + THROW_MQEXCEPTION(MQClientException, failed_detail, -1); + } string info = "No route info of this topic: " + msg.getTopic(); THROW_MQEXCEPTION(MQClientException, info, -1); } @@ -540,6 +549,8 @@ SendResult DefaultMQProducerImpl::sendAutoRetrySelectImpl(MQMessage& msg, MQMessageQueue lastmq; MQMessageQueue mq; int mq_index = 0; + bool send_failed = false; + string failed_detail; for (int times = 1; times <= autoRetryTimes + 1; times++) { boost::weak_ptr<TopicPublishInfo> weak_topicPublishInfo( getFactory()->tryToFindTopicPublishInfo(msg.getTopic(), getSessionCredentials())); @@ -588,15 +599,22 @@ SendResult DefaultMQProducerImpl::sendAutoRetrySelectImpl(MQMessage& msg, default: break; } - } catch (...) { - LOG_ERROR("send failed of times:%d,mq:%s", times, mq.toString().c_str()); + } catch (std::exception& e) { + send_failed = true; + failed_detail = e.what(); + LOG_ERROR("send failed of times:%d,mq:%s,details:%s", times, mq.toString().c_str(), e.what()); if (bActiveMQ) { topicPublishInfo->updateNonServiceMessageQueue(mq, getSendMsgTimeout()); } continue; + } catch (...) { + LOG_ERROR("An unknown exception occurred,send failed of times:%d,mq:%s", times, mq.toString().c_str()); } } // end of for LOG_WARN("Retry many times, still failed"); + if (send_failed) { + THROW_MQEXCEPTION(MQClientException, failed_detail, -1); + } } THROW_MQEXCEPTION(MQClientException, "No route info of this topic, ", -1); }