@@ -100,10 +100,18 @@ class CPPKAFKA_API BackoffCommitter : public BackoffPerformer {
100100 */
101101 void set_error_callback (ErrorCallback callback);
102102
103+ /* *
104+ * \brief Commits the current partition assignment synchronously
105+ *
106+ * This will call Consumer::commit() until either the message is successfully
107+ * committed or the error callback returns false (if any is set).
108+ */
109+ void commit ();
110+
103111 /* *
104112 * \brief Commits the given message synchronously
105113 *
106- * This will call Consumer::commit until either the message is successfully
114+ * This will call Consumer::commit(msg) until either the message is successfully
107115 * committed or the error callback returns false (if any is set).
108116 *
109117 * \param msg The message to be committed
@@ -113,7 +121,7 @@ class CPPKAFKA_API BackoffCommitter : public BackoffPerformer {
113121 /* *
114122 * \brief Commits the offsets on the given topic/partitions synchronously
115123 *
116- * This will call Consumer::commit until either the offsets are successfully
124+ * This will call Consumer::commit(topic_partitions) until either the offsets are successfully
117125 * committed or the error callback returns false (if any is set).
118126 *
119127 * \param topic_partitions The topic/partition list to be committed
@@ -127,25 +135,30 @@ class CPPKAFKA_API BackoffCommitter : public BackoffPerformer {
127135 */
128136 Consumer& get_consumer ();
129137private:
130- // Return true to abort and false to continue committing
131- template <typename T>
132- bool do_commit (const T& object) {
138+ // If the ReturnType contains 'true', we abort committing. Otherwise we continue.
139+ // The second member of the ReturnType contains the RdKafka error if any.
140+ template <typename ...Args>
141+ bool do_commit (Args&&...args) {
133142 try {
134- consumer_.commit (object );
135- // If the commit succeeds, we're done
143+ consumer_.commit (std::forward<Args>(args)... );
144+ // If the commit succeeds, we're done.
136145 return true ;
137146 }
138147 catch (const HandleException& ex) {
148+ Error error = ex.get_error ();
139149 // If there were actually no offsets to commit, return. Retrying won't solve
140- // anything here
141- if (ex. get_error () == RD_KAFKA_RESP_ERR__NO_OFFSET) {
142- return true ;
150+ // anything here.
151+ if (error == RD_KAFKA_RESP_ERR__NO_OFFSET) {
152+ return true ; // not considered an error.
143153 }
144154 // If there's a callback and it returns false for this message, abort.
145155 // Otherwise keep committing.
146156 CallbackInvoker<ErrorCallback> callback (" backoff committer" , callback_, &consumer_);
147- return callback && !callback (ex.get_error ());
157+ if (callback && !callback (error)) {
158+ throw ex; // abort
159+ }
148160 }
161+ return false ; // continue
149162 }
150163
151164 Consumer& consumer_;
0 commit comments