This is an automated email from the ASF dual-hosted git repository.

lizhanhui pushed a commit to branch fifo_opt
in repository https://gitbox.apache.org/repos/asf/rocketmq-clients.git


The following commit(s) were added to refs/heads/fifo_opt by this push:
     new c5de9af3 fix: add doc explaining why we taking ownership of the 
message being sent
c5de9af3 is described below

commit c5de9af366319e3938080455a6b3b5744f418d12
Author: Li Zhanhui <[email protected]>
AuthorDate: Sun Apr 14 17:54:24 2024 +0800

    fix: add doc explaining why we taking ownership of the message being sent
    
    Signed-off-by: Li Zhanhui <[email protected]>
---
 cpp/examples/ExampleProducerWithAsync.cpp  |  1 -
 cpp/examples/ExamplePushConsumer.cpp       |  1 -
 cpp/examples/ExampleSimpleConsumer.cpp     |  1 -
 cpp/source/rocketmq/ProducerImpl.cpp       |  4 ++++
 cpp/source/rocketmq/include/ProducerImpl.h | 23 +++++++++++++++++++++++
 5 files changed, 27 insertions(+), 3 deletions(-)

diff --git a/cpp/examples/ExampleProducerWithAsync.cpp 
b/cpp/examples/ExampleProducerWithAsync.cpp
index 63b7611c..d88dfc85 100644
--- a/cpp/examples/ExampleProducerWithAsync.cpp
+++ b/cpp/examples/ExampleProducerWithAsync.cpp
@@ -17,7 +17,6 @@
 #include <algorithm>
 #include <atomic>
 #include <condition_variable>
-#include <cstdint>
 #include <iostream>
 #include <mutex>
 #include <random>
diff --git a/cpp/examples/ExamplePushConsumer.cpp 
b/cpp/examples/ExamplePushConsumer.cpp
index ab106cb7..66a85f4b 100644
--- a/cpp/examples/ExamplePushConsumer.cpp
+++ b/cpp/examples/ExamplePushConsumer.cpp
@@ -16,7 +16,6 @@
  */
 #include <chrono>
 #include <iostream>
-#include <mutex>
 #include <thread>
 
 #include "gflags/gflags.h"
diff --git a/cpp/examples/ExampleSimpleConsumer.cpp 
b/cpp/examples/ExampleSimpleConsumer.cpp
index 17a84b78..aedec71e 100644
--- a/cpp/examples/ExampleSimpleConsumer.cpp
+++ b/cpp/examples/ExampleSimpleConsumer.cpp
@@ -16,7 +16,6 @@
  */
 #include <chrono>
 #include <iostream>
-#include <thread>
 
 #include "gflags/gflags.h"
 #include "rocketmq/Logger.h"
diff --git a/cpp/source/rocketmq/ProducerImpl.cpp 
b/cpp/source/rocketmq/ProducerImpl.cpp
index 04fc6266..34975e71 100644
--- a/cpp/source/rocketmq/ProducerImpl.cpp
+++ b/cpp/source/rocketmq/ProducerImpl.cpp
@@ -250,6 +250,7 @@ void ProducerImpl::send(MessageConstPtr message, 
SendCallback cb) {
   ensureRunning(ec);
   if (ec) {
     SendReceipt send_receipt;
+    send_receipt.message = std::move(message);
     cb(ec, send_receipt);
   }
 
@@ -263,6 +264,7 @@ void ProducerImpl::send(MessageConstPtr message, 
SendCallback cb) {
     // No route entries of the given topic is available
     if (ec) {
       SendReceipt send_receipt;
+      send_receipt.message = std::move(ptr);
       cb(ec, send_receipt);
       return;
     }
@@ -270,6 +272,7 @@ void ProducerImpl::send(MessageConstPtr message, 
SendCallback cb) {
     if (!publish_info) {
       std::error_code ec = ErrorCode::NotFound;
       SendReceipt     send_receipt;
+      send_receipt.message = std::move(ptr);
       cb(ec, send_receipt);
       return;
     }
@@ -279,6 +282,7 @@ void ProducerImpl::send(MessageConstPtr message, 
SendCallback cb) {
     if (!publish_info->selectMessageQueues(ptr->group(), message_queue_list)) {
       std::error_code ec = ErrorCode::NotFound;
       SendReceipt     send_receipt;
+      send_receipt.message = std::move(ptr);
       cb(ec, send_receipt);
       return;
     }
diff --git a/cpp/source/rocketmq/include/ProducerImpl.h 
b/cpp/source/rocketmq/include/ProducerImpl.h
index a75c3444..d51bfc0e 100644
--- a/cpp/source/rocketmq/include/ProducerImpl.h
+++ b/cpp/source/rocketmq/include/ProducerImpl.h
@@ -48,8 +48,22 @@ public:
 
   void shutdown() override;
 
+  /**
+   * Note we requrie application to transfer ownership of the message to send 
to avoid concurrent modification during
+   * sent.
+   *
+   * Regardless of the send result, SendReceipt would have the 
std::unique_ptr<const Message>, facilliating
+   * application to conduct customized retry policy.
+   */
   SendReceipt send(MessageConstPtr message, std::error_code& ec) noexcept;
 
+  /**
+   * Note we requrie application to transfer ownership of the message to send 
to avoid concurrent modification during
+   * sent.
+   *
+   * Regardless of the send result, SendReceipt would have the 
std::unique_ptr<const Message>, facilliating
+   * application to conduct customized retry policy.
+   */
   void send(MessageConstPtr message, SendCallback callback);
 
   void setTransactionChecker(TransactionChecker checker);
@@ -59,6 +73,15 @@ public:
     return absl::make_unique<TransactionImpl>(producer);
   }
 
+  /**
+   * Note we requrie application to transfer ownership of the message to send 
to avoid concurrent modification during
+   * sent.
+   *
+   * Regardless of the send result, SendReceipt would have the 
std::unique_ptr<const Message>, facilliating
+   * application to conduct customized retry policy.
+   *
+   * TODO: Refine this API.
+   */
   void send(MessageConstPtr message, std::error_code& ec, Transaction& 
transaction);
 
   /**

Reply via email to