mirror of
https://github.com/Telecominfraproject/wlan-cloud-lib-cppkafka.git
synced 2025-11-02 19:47:55 +00:00
Replaced termination callback with throwing exception
This commit is contained in:
@@ -100,10 +100,18 @@ public:
|
||||
*/
|
||||
void set_error_callback(ErrorCallback callback);
|
||||
|
||||
/**
|
||||
* \brief Commits the current partition assignment synchronously
|
||||
*
|
||||
* This will call Consumer::commit() until either the message is successfully
|
||||
* committed or the error callback returns false (if any is set).
|
||||
*/
|
||||
void commit();
|
||||
|
||||
/**
|
||||
* \brief Commits the given message synchronously
|
||||
*
|
||||
* This will call Consumer::commit until either the message is successfully
|
||||
* This will call Consumer::commit(msg) until either the message is successfully
|
||||
* committed or the error callback returns false (if any is set).
|
||||
*
|
||||
* \param msg The message to be committed
|
||||
@@ -113,7 +121,7 @@ public:
|
||||
/**
|
||||
* \brief Commits the offsets on the given topic/partitions synchronously
|
||||
*
|
||||
* This will call Consumer::commit until either the offsets are successfully
|
||||
* This will call Consumer::commit(topic_partitions) until either the offsets are successfully
|
||||
* committed or the error callback returns false (if any is set).
|
||||
*
|
||||
* \param topic_partitions The topic/partition list to be committed
|
||||
@@ -127,25 +135,34 @@ public:
|
||||
*/
|
||||
Consumer& get_consumer();
|
||||
private:
|
||||
// Return true to abort and false to continue committing
|
||||
// If the ReturnType contains 'true', we abort committing. Otherwise we continue.
|
||||
// The second member of the ReturnType contains the RdKafka error if any.
|
||||
template <typename T>
|
||||
bool do_commit(const T& object) {
|
||||
ReturnType do_commit(const T* object) {
|
||||
ReturnType rt;
|
||||
try {
|
||||
consumer_.commit(object);
|
||||
// If the commit succeeds, we're done
|
||||
return true;
|
||||
if (!object) {
|
||||
consumer_.commit();
|
||||
}
|
||||
else {
|
||||
consumer_.commit(*object);
|
||||
}
|
||||
// If the commit succeeds, we're done.
|
||||
}
|
||||
catch (const HandleException& ex) {
|
||||
rt.error_ = ex.get_error();
|
||||
// If there were actually no offsets to commit, return. Retrying won't solve
|
||||
// anything here
|
||||
if (ex.get_error() == RD_KAFKA_RESP_ERR__NO_OFFSET) {
|
||||
return true;
|
||||
if (rt.error_ != RD_KAFKA_RESP_ERR__NO_OFFSET) {
|
||||
// If there's no callback or if returns true for this message, keep committing.
|
||||
// Otherwise abort.
|
||||
CallbackInvoker<ErrorCallback> callback("backoff committer", callback_, &consumer_);
|
||||
if (!callback || callback(rt.error_)) {
|
||||
rt.abort_ = false; //continue retrying
|
||||
}
|
||||
}
|
||||
// If there's a callback and it returns false for this message, abort.
|
||||
// Otherwise keep committing.
|
||||
CallbackInvoker<ErrorCallback> callback("backoff committer", callback_, &consumer_);
|
||||
return callback && !callback(ex.get_error());
|
||||
}
|
||||
return rt;
|
||||
}
|
||||
|
||||
Consumer& consumer_;
|
||||
|
||||
Reference in New Issue
Block a user