jonnxu commented on a change in pull request #48: [Issue#44] Resolve 
RetrySendTimes doesn't Work for Async Send
URL: https://github.com/apache/rocketmq-client-cpp/pull/48#discussion_r245180012
 
 

 ##########
 File path: src/MQClientAPIImpl.cpp
 ##########
 @@ -411,13 +410,38 @@ void MQClientAPIImpl::sendMessageAsync(const string& 
addr,
                                        const MQMessage& msg,
                                        RemotingCommand& request,
                                        SendCallback* pSendCallback,
-                                       int64 timeoutMilliseconds) {
+                                       int64 timeoutMilliseconds,
+                                       int maxRetryTimes,
+                                       int retrySendTimes) {
+  int64 begin_time = UtilAll::currentTimeMillis();
   //<!delete in future;
-  AsyncCallbackWrap* cbw =
-      new SendCallbackWrap(brokerName, msg, pSendCallback, this);
-  if (m_pRemotingClient->invokeAsync(addr, request, cbw, timeoutMilliseconds) 
==
+  AsyncCallbackWrap* cbw = new SendCallbackWrap(brokerName, msg, 
pSendCallback, this);
+
+  LOG_DEBUG("sendMessageAsync request:%s, timeout:%lld, maxRetryTimes:%d 
retrySendTimes:%d", request.ToString().data(), timeoutMilliseconds, 
maxRetryTimes, retrySendTimes);
+  
+  if (m_pRemotingClient->invokeAsync(addr, request, cbw, timeoutMilliseconds, 
maxRetryTimes, retrySendTimes) ==
       false) {
-    LOG_ERROR("sendMessageAsync failed to addr:%s", addr.c_str());
+    LOG_WARN("invokeAsync failed to addr:%s,topic:%s, timeout:%lld, 
maxRetryTimes:%d, retrySendTimes:%d", 
+               addr.c_str(), msg.getTopic().data(), timeoutMilliseconds, 
maxRetryTimes, retrySendTimes);
+       //when getTcp return false, need consider retrySendTimes
+       int retry_time = retrySendTimes + 1;
+       int64 time_out = timeoutMilliseconds - (UtilAll::currentTimeMillis() - 
begin_time);
+       while (retry_time < maxRetryTimes && time_out > 0) {
+               begin_time = UtilAll::currentTimeMillis();
+               if (m_pRemotingClient->invokeAsync(addr, request, cbw, 
time_out, maxRetryTimes, retry_time) == false) {
+                       retry_time += 1;
+                       time_out = time_out - (UtilAll::currentTimeMillis() - 
begin_time);
+                       LOG_WARN("invokeAsync retry failed to addr:%s,topic:%s, 
timeout:%lld, maxRetryTimes:%d, retrySendTimes:%d", 
+                               addr.c_str(), msg.getTopic().data(), time_out, 
maxRetryTimes, retry_time);
+                       continue;
+               } else {
+                       return; //invokeAsync success
 
 Review comment:
   here no need, because normally it will success, if it fail ,there is a 
warning log in the retry section and a error log after retry section

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services

Reply via email to