The KIP-848 protocol is fully incremental. If you use rebalance callbacks, you must switch from full assignment methods to incremental ones.
Important Changes:
- Use
consumer.IncrementalAssign(e.Partitions) to assign new partitions. - Use
consumer.IncrementalUnassign(e.Partitions) to revoke partitions. - Do not use
consumer.Assign() or consumer.Unassign() after subscribing with group.protocol='consumer'. - The
e.Partitions list in KIP-848 contains only the incremental changes (the specific partitions being added or revoked), unlike the classic protocol which provided the full assignment.
If you do not call these methods manually, the client will handle the incremental assignment internally.
// Incremental assignor for KIP-848
func onRebalanceCooperative(consumer *kafka.Consumer, ev kafka.Event) {
switch e := ev.(type) {
case kafka.AssignedPartitions:
fmt.Printf("[KIP-848] Incrementally assigning: %v\n", e.Partitions)
// Optional: client handles if omitted
consumer.IncrementalAssign(e.Partitions)
case kafka.RevokedPartitions:
fmt.Printf("[KIP-848] Incrementally revoking: %v\n", e.Partitions)
// Optional: client handles if omitted
consumer.IncrementalUnassign(e.Partitions)
}
}