Open justjake opened 1 month ago
This is correct, at the moment, pause() can't be called from within the rebalance callback.
The current logic for when we receive partition assignments from the broker is: call user defined rebalance cb, and then "assign" partitions to the internal library. Before this assign, these partitions aren't counted within the assignment of the consumer.
Pause only pauses those topic partitions which are within the assignment. So it doesn't work from within the callback.
This is necessary because the user is allowed to change the assignment within the rebalance callback, so assigning before the callback isn't possible.
We're discussing this internally, there are two things possible;
I'm also seeing if we can make the error handling for pause a little better, if there is a way to return a per-partition result in case a partition was not paused.
Thanks for the report!
Ok, that makes sense. I only expected “pause during rebalance_cb” to work because a Confluence support engineer suggested it. Maybe I misunderstood their guidance.
We discussed this within the team, we'll be exposing assign/unassign and their incremental variants to allow for this use case, so you'll be able to pause within the rebalance cb.
I'll check internally about the guidance, maybe there was a misunderstanding as this sort of an operation is supported within librdkafka.
Alright, I merged a PR which allows doing this, something like so:
rebalance_cb: function (err, assignment, assignmentFns) {
if (err.code === ErrorCodes.ERR__ASSIGN_PARTITIONS) {
/* Assign first so we can pause. */
assignmentFns.assign(assignment);
/* Convert the assignment into format suitable for pause argument. */
const pausablePartitions = [{ topic: topicName, partitions: [0, 1, 2] }];
consumer.pause(pausablePartitions);
} else { // This isn't strictly necessary - the library will call assign/unassign for you if you don't do it yourself.
assignmentFns.unassign(assignment);
}
}
It'll be available in the next release
Environment Information
"@confluentinc/kafka-javascript": "0.1.16-devel"
Steps to Reproduce
Here's the console output I get: