BewareMyPower commented on code in PR #17429:
URL: https://github.com/apache/pulsar/pull/17429#discussion_r976168048


##########
pulsar-client-cpp/include/pulsar/Messages.h:
##########
@@ -0,0 +1,51 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+#ifndef MESSAGES_HPP_
+#define MESSAGES_HPP_
+
+#include <pulsar/defines.h>
+#include <vector>
+#include <memory>
+
+namespace pulsar {
+
+class Message;
+class MessagesImpl;
+
+class PULSAR_PUBLIC Messages {
+   public:
+    Messages();
+
+    /**
+     * Get message list.
+     *
+     * @return message list.
+     */
+    std::vector<Message> getMessageList() const;

Review Comment:
   It's not a good API design. `getMessageList` returns a copy of `Message` 
objects and it's over-designed. You can see `Messages` is an `Iterable` 
interface in Java so that the underlying implementation can be flexible.
   
   IMO, as a C++ user, I tend to use the `batchReceive` API like:
   
   ```c++
   Messages messages;
   // Here we ignore the returned result for simplicity
   consumer.batchReceive(messages);
   for (const auto& message : messages) {
       // process message...
   }
   ```
   
   or more functional programming style:
   
   ```c++
   messages.forEach([](const Message& message) {/* ... */});
   ```
   
   But for simplicity here, you can just change the `Consumer::batchReceive` 
signature to:
   
   ```c++
   Result batchReceive(std::vector<Message>& messages);
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to