-
Notifications
You must be signed in to change notification settings - Fork 627
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
auto commit and add event for rebalance #889
Conversation
Should resolve SOHU-Co#787 If auto commit is true, commit before we rejoin the group on a rebalance According to the kafka protcol, commits are allowed during this stage, as the generation ID has not been bumped yet. If auto commit is disabled, implementors need a way to decide what to commit, so an onRebalance option was added. Implementors can perform commits during this method and call back when done to finish the rebalance.
This required special behavior due to the separate commit queue
commit(null, true) will flush what was already in the queue.
This should be good to go now (Travis has been pretty unreliable lately, test did pass) An example of using the onRebalance event: async _onRebalance(isMember: boolean, cb: Function) {
try {
if (isMember) {
this.logger.info("Rebalancing");
// Clear and wait for any pending event dispatches, giving them a chance to commit
await this._clearAndWaitForQueue();
// Now any pending tasks are in the commit queue, which will be picked up after this method finishes
}
this.emit("kafka:rebalance");
} catch (e) {
this.logger.error("ErrorKafkaRebalance", e);
} finally {
cb();
}
} |
@hyperlink is anything holding this up? |
lib/consumerGroupStream.js
Outdated
const originalOnRebalance = options.onRebalance; | ||
options.onRebalance = function (isAlreadyMember, callback) { | ||
let autoCommitCalled = false; | ||
const autoCommit = function (err) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could warp this in _.once
to avoid having a flag.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for your contribution!
@hyperlink dear Sir, any plans to release this? |
@hugebdu I will get it prepared. |
@hugebdu holding off for now. I'm tracking down an error when running the tests locally. |
@hyperlink 10x for update. waiting patiently |
Published as 2.5.0. |
@hyperlink thanks a lot! |
Should resolve #787
If auto commit is true, commit before we rejoin the group on a rebalance
According to the kafka protcol, commits are allowed during this stage, as the generation ID has not been bumped yet.
If auto commit is disabled, implementors need a way to decide what to commit, so an onRebalance option was added.
Implementors can perform commits during this method and call back when done to finish the rebalance.