Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ISSUE #485]fix: send failed show exception details #486

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/MQClientAPIImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
26 changes: 22 additions & 4 deletions src/producer/DefaultMQProducerImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()));
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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()));
Expand Down Expand Up @@ -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);
}
Expand Down