Add cooperative rebalancing consumer example#2248
Open
jmathai-confluent wants to merge 1 commit into
Open
Conversation
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
|
🎉 All Contributor License Agreements have been signed. Ready to merge. |
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.





Summary
Adds a new
cooperative_consumer.pyexample demonstrating how to use the cooperative-sticky partition assignment strategy with incremental rebalance callbacks (on_assign,on_revoke,on_lost). This is a commonly requested example that shows how cooperative rebalancing differs from the default eager strategy.Fixes #1420
Example overview
The example creates a consumer configured with
partition.assignment.strategy: cooperative-stickyand subscribes to one or more topics. It demonstrates:on_assign— logs partitions as they are incrementally assignedon_revoke— commits offsets for only the partitions being transferred to another consumer (other partitions continue processing without interruption)on_lost— handles partitions lost due to session/poll timeout (no commit attempted since the consumer is no longer in the group)on_lostis important when committing inon_revokeUsage:
python cooperative_consumer.py <bootstrap-brokers> <group> <topic1> [<topic2> ..]Verification script
A verification script (
verify_example.sh) validates the example without requiring a running Kafka broker.Expected output
The script should print PASS for all 5 checks: file exists, compiles, callbacks defined, cooperative-sticky configured, and usage message on bad args.
Actual output
Script
🤖 Generated with Claude Code