rocketmq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ifplu...@apache.org
Subject [rocketmq-client-cpp] 15/29: refactor: MQMessageExt::from_list
Date Tue, 29 Dec 2020 03:36:32 GMT
This is an automated email from the ASF dual-hosted git repository.

ifplusor pushed a commit to branch re_dev
in repository https://gitbox.apache.org/repos/asf/rocketmq-client-cpp.git

commit a281df90ef3c3656b75b294627c4c60f4aae6dfc
Author: James Yin <ywhjames@hotmail.com>
AuthorDate: Mon Sep 21 15:27:31 2020 +0800

    refactor: MQMessageExt::from_list
---
 include/MQMessageExt.h                             | 3 +++
 src/consumer/ConsumeMessageConcurrentlyService.cpp | 6 +-----
 src/consumer/ConsumeMessageOrderlyService.cpp      | 6 +-----
 src/message/MQMessageExt.cpp                       | 9 +++++++++
 4 files changed, 14 insertions(+), 10 deletions(-)

diff --git a/include/MQMessageExt.h b/include/MQMessageExt.h
index d00ea94..0599c06 100644
--- a/include/MQMessageExt.h
+++ b/include/MQMessageExt.h
@@ -29,6 +29,9 @@ class ROCKETMQCLIENT_API MQMessageExt : public MQMessage,          // base
                                         virtual public MessageExt  // interface
 {
  public:
+  static std::vector<MQMessageExt> from_list(std::vector<MessageExtPtr>&
msg_list);
+
+ public:
   MQMessageExt();
   MQMessageExt(int queueId,
                int64_t bornTimestamp,
diff --git a/src/consumer/ConsumeMessageConcurrentlyService.cpp b/src/consumer/ConsumeMessageConcurrentlyService.cpp
index 16d725b..ffbf892 100755
--- a/src/consumer/ConsumeMessageConcurrentlyService.cpp
+++ b/src/consumer/ConsumeMessageConcurrentlyService.cpp
@@ -88,11 +88,7 @@ void ConsumeMessageConcurrentlyService::ConsumeRequest(std::vector<MessageExtPtr
         MessageAccessor::setConsumeStartTimeStamp(*msg, timestamp);
       }
     }
-    std::vector<MQMessageExt> message_list;
-    message_list.reserve(msgs.size());
-    for (const auto& msg : msgs) {
-      message_list.emplace_back(msg);
-    }
+    auto message_list = MQMessageExt::from_list(msgs);
     status = message_listener_->consumeMessage(message_list);
   } catch (const std::exception& e) {
     LOG_WARN_NEW("encounter unexpected exception when consume messages.\n{}", e.what());
diff --git a/src/consumer/ConsumeMessageOrderlyService.cpp b/src/consumer/ConsumeMessageOrderlyService.cpp
index 0dd2c16..a14431e 100755
--- a/src/consumer/ConsumeMessageOrderlyService.cpp
+++ b/src/consumer/ConsumeMessageOrderlyService.cpp
@@ -158,11 +158,7 @@ void ConsumeMessageOrderlyService::ConsumeRequest(ProcessQueuePtr processQueue,
                          messageQueue.toString());
             break;
           }
-          std::vector<MQMessageExt> message_list;
-          message_list.reserve(msgs.size());
-          for (const auto& msg : msgs) {
-            message_list.emplace_back(msg);
-          }
+          auto message_list = MQMessageExt::from_list(msgs);
           status = message_listener_->consumeMessage(message_list);
         } catch (const std::exception& e) {
           LOG_WARN_NEW("encounter unexpected exception when consume messages.\n{}", e.what());
diff --git a/src/message/MQMessageExt.cpp b/src/message/MQMessageExt.cpp
index a58d035..92e8b8e 100644
--- a/src/message/MQMessageExt.cpp
+++ b/src/message/MQMessageExt.cpp
@@ -21,6 +21,15 @@
 
 namespace rocketmq {
 
+std::vector<MQMessageExt> MQMessageExt::from_list(std::vector<MessageExtPtr>&
msg_list) {
+  std::vector<MQMessageExt> message_list;
+  message_list.reserve(msg_list.size());
+  for (const auto& msg : msg_list) {
+    message_list.emplace_back(msg);
+  }
+  return message_list;
+}
+
 MQMessageExt::MQMessageExt() : MQMessageExt(0, 0, nullptr, 0, nullptr, null) {}
 
 MQMessageExt::MQMessageExt(int queueId,


Mime
View raw message