Skip to content

Commit

Permalink
Drain the queue on rebalance
Browse files Browse the repository at this point in the history
This should ensure the offsets are stored (and commited) on rebalance.

Issue: BB-441
  • Loading branch information
francoisferrand committed Oct 5, 2023
1 parent 4f4ee02 commit 465c9ed
Showing 1 changed file with 19 additions and 10 deletions.
29 changes: 19 additions & 10 deletions lib/BackbeatConsumer.js
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,25 @@ class BackbeatConsumer extends EventEmitter {
'offset_commit_cb': this._onOffsetCommit.bind(this),
// automatically create topic
'allow.auto.create.topics': true,
'rebalance_cb': true,
'rebalance_cb': (err, assignment) => {

Check warning on line 182 in lib/BackbeatConsumer.js

View workflow job for this annotation

GitHub Actions / tests

Expected to return a value at the end of method 'rebalance_cb'
if (err.code === kafka.CODES.ERRORS.ERR__ASSIGN_PARTITIONS) {
this._log.debug('rdkafka.assign', { err, assignment });
this._consumer.assign(assignment);
} else if (err.code === kafka.CODES.ERRORS.ERR__REVOKE_PARTITIONS) {
this._log.debug('rdkafka.revoke', { err });

if (!this._processingQueue || this._processingQueue.empty()) {
return this._consumer.unassign();
}

this._processingQueue.drain(() => {
this._log.debug('processing queue drained, un-assigning');
this._consumer.unassign();
});
} else {
this._log.error('rdkafka.rebalance', { err, assignment });
}
},
};
const topicParams = {};
if (this._fromOffset !== undefined) {
Expand All @@ -206,15 +224,6 @@ class BackbeatConsumer extends EventEmitter {
this._consumer.on('warning', warning => this._log.warn('rdkafka.warning', { warning }));
this._consumer.on('event.error', err => this._log.error('rdkafka.error', { err }));
this._consumer.on('event.throttle', throttle => this._log.info('rdkafka.throttle', { throttle }));
this._consumer.on('rebalance', (err, assignment) => {
if (err.code === kafka.CODES.ERRORS.ERR__ASSIGN_PARTITIONS) {
this._log.debug('rdkafka.assign', { err, assignment });
} else if (err.code === kafka.CODES.ERRORS.ERR__REVOKE_PARTITIONS) {
this._log.debug('rdkafka.revoke', { err });
} else {
this._log.error('rdkafka.rebalance', { err, assignment });
}
});

this._connect();
}
Expand Down

0 comments on commit 465c9ed

Please sign in to comment.