-
Notifications
You must be signed in to change notification settings - Fork 952
[KIP-932] : Implement Share consumer interface with poll API #2217
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Kaushik Raina (k-raina)
merged 25 commits into
dev_kip-932_queues-for-kafka
from
dev_kip-932_share_consumer_poll
May 13, 2026
Merged
Changes from all commits
Commits
Show all changes
25 commits
Select commit
Hold shift + click to select a range
51ec85d
KIP-932 : Implement Share consumer interface with poll API
k-raina fc5ef4f
BUILD-KIP932: Commit to build branch with kip-932 librdkafka branch
k-raina e23df2e
Address copilor comments
k-raina 88b4a3a
Address first pass feedback
k-raina 852d090
Style fix
k-raina d59b196
Style fix
k-raina 48208f4
Address feedback
k-raina 1e41691
Address feedback
k-raina 59db830
Merge remote-tracking branch 'origin/master' into dev_kip-932_share_c…
k-raina 9580e6d
Style fix
k-raina 6991299
Address feedback
k-raina 5b4b408
Move integration tests
k-raina cabc157
minor
k-raina 1e1fe37
Fix semaphore
k-raina 62021da
Test share consumer
k-raina f32e19c
Fix broker_conf for KIP-932 and resolve broker_version inconsistencies
k-raina 901697c
Address feedback
k-raina 5f4bc3b
Fix build
k-raina 282d38f
Fix build
k-raina cc940c2
Clean up
k-raina d4d1456
Style fix
k-raina 5da8354
Address feedbacks
k-raina ee8e8c6
Minor fix
k-raina 8d2b43b
Add TODOs
k-raina f8c54f7
Add TODOs
k-raina File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,75 @@ | ||
| #!/usr/bin/env python | ||
| # | ||
| # Copyright 2026 Confluent Inc. | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
| # | ||
|
|
||
| import sys | ||
|
|
||
| # | ||
| # Example KIP-932 ShareConsumer. | ||
| # | ||
| # A share consumer reads from one or more topics like a queue: many consumers | ||
| # in the same share group can read the same partition, and each record is | ||
| # acknowledged implicitly. | ||
| # | ||
| from confluent_kafka import ShareConsumer | ||
|
|
||
|
|
||
| def print_usage_and_exit(program_name): | ||
| sys.stderr.write('Usage: %s <bootstrap-brokers> <group> <topic1> <topic2> ..\n' % program_name) | ||
| sys.exit(1) | ||
|
|
||
|
|
||
| if __name__ == '__main__': | ||
| if len(sys.argv) < 4: | ||
| print_usage_and_exit(sys.argv[0]) | ||
|
|
||
| broker = sys.argv[1] | ||
| group = sys.argv[2] | ||
| topics = sys.argv[3:] | ||
|
|
||
| # ShareConsumer configuration. | ||
| # See https://github.com/confluentinc/librdkafka/blob/master/CONFIGURATION.md | ||
| conf = { | ||
| 'bootstrap.servers': broker, | ||
| 'group.id': group, | ||
| } | ||
|
|
||
| sc = ShareConsumer(conf) | ||
| sc.subscribe(topics) | ||
|
|
||
| try: | ||
| while True: | ||
| messages = sc.poll(timeout=1.0) # returns a list (possibly empty) | ||
| for msg in messages: | ||
| if msg.error(): | ||
| # Per-message errors are informational; log and keep | ||
| # polling. Truly fatal errors are raised out of poll() | ||
| # itself via the error_cb path. | ||
| sys.stderr.write('%% Error: %s\n' % msg.error()) | ||
| continue | ||
| sys.stderr.write( | ||
| '%% %s [%d] at offset %d with key %s:\n' | ||
| % (msg.topic(), msg.partition(), msg.offset(), str(msg.key())) | ||
| ) | ||
| print(msg.value()) | ||
| # Implicit ack: the next poll() acknowledges this message. | ||
| # If we crash before the next poll, the broker will | ||
| # redeliver this record to another consumer in the share | ||
| # group after the acquisition lock expires. | ||
| except KeyboardInterrupt: | ||
| sys.stderr.write('%% Aborted by user\n') | ||
| finally: | ||
| sc.close() |
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
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add an example file |
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -63,12 +63,14 @@ class KafkaError: | |
| DELEGATION_TOKEN_REQUEST_NOT_ALLOWED: int | ||
| DUPLICATE_RESOURCE: int | ||
| DUPLICATE_SEQUENCE_NUMBER: int | ||
| DUPLICATE_VOTER: int | ||
|
pranavrth marked this conversation as resolved.
|
||
| ELECTION_NOT_NEEDED: int | ||
| ELIGIBLE_LEADERS_NOT_AVAILABLE: int | ||
| FEATURE_UPDATE_FAILED: int | ||
| FENCED_INSTANCE_ID: int | ||
| FENCED_LEADER_EPOCH: int | ||
| FENCED_MEMBER_EPOCH: int | ||
| FENCED_STATE_EPOCH: int | ||
| FETCH_SESSION_ID_NOT_FOUND: int | ||
| GROUP_AUTHORIZATION_FAILED: int | ||
| GROUP_ID_NOT_FOUND: int | ||
|
|
@@ -89,20 +91,26 @@ class KafkaError: | |
| INVALID_PRODUCER_EPOCH: int | ||
| INVALID_PRODUCER_ID_MAPPING: int | ||
| INVALID_RECORD: int | ||
| INVALID_RECORD_STATE: int | ||
| INVALID_REGISTRATION: int | ||
| INVALID_REGULAR_EXPRESSION: int | ||
| INVALID_REPLICATION_FACTOR: int | ||
| INVALID_REPLICA_ASSIGNMENT: int | ||
| INVALID_REQUEST: int | ||
| INVALID_REQUIRED_ACKS: int | ||
| INVALID_SHARE_SESSION_EPOCH: int | ||
| INVALID_SESSION_TIMEOUT: int | ||
| INVALID_TIMESTAMP: int | ||
| INVALID_TRANSACTION_TIMEOUT: int | ||
| INVALID_TXN_STATE: int | ||
| INVALID_UPDATE_VERSION: int | ||
| INVALID_VOTER_KEY: int | ||
| KAFKA_STORAGE_ERROR: int | ||
| LEADER_NOT_AVAILABLE: int | ||
| LISTENER_NOT_FOUND: int | ||
| LOG_DIR_NOT_FOUND: int | ||
| MEMBER_ID_REQUIRED: int | ||
| MISMATCHED_ENDPOINT_TYPE: int | ||
| MSG_SIZE_TOO_LARGE: int | ||
| NETWORK_EXCEPTION: int | ||
| NON_EMPTY_GROUP: int | ||
|
|
@@ -131,19 +139,26 @@ class KafkaError: | |
| RESOURCE_NOT_FOUND: int | ||
| SASL_AUTHENTICATION_FAILED: int | ||
| SECURITY_DISABLED: int | ||
| SHARE_SESSION_LIMIT_REACHED: int | ||
| SHARE_SESSION_NOT_FOUND: int | ||
| STALE_BROKER_EPOCH: int | ||
| STALE_CTRL_EPOCH: int | ||
| STALE_MEMBER_EPOCH: int | ||
| STREAMS_INVALID_TOPOLOGY: int | ||
| STREAMS_INVALID_TOPOLOGY_EPOCH: int | ||
| STREAMS_TOPOLOGY_FENCED: int | ||
| TELEMETRY_TOO_LARGE: int | ||
| THROTTLING_QUOTA_EXCEEDED: int | ||
| TOPIC_ALREADY_EXISTS: int | ||
| TOPIC_AUTHORIZATION_FAILED: int | ||
| TOPIC_DELETION_DISABLED: int | ||
| TOPIC_EXCEPTION: int | ||
| TRANSACTION_ABORTABLE: int | ||
| TRANSACTIONAL_ID_AUTHORIZATION_FAILED: int | ||
| TRANSACTION_COORDINATOR_FENCED: int | ||
| UNACCEPTABLE_CREDENTIAL: int | ||
| UNKNOWN: int | ||
| UNKNOWN_CONTROLLER_ID: int | ||
| UNKNOWN_LEADER_EPOCH: int | ||
| UNKNOWN_MEMBER_ID: int | ||
| UNKNOWN_PRODUCER_ID: int | ||
|
|
@@ -154,9 +169,11 @@ class KafkaError: | |
| UNSTABLE_OFFSET_COMMIT: int | ||
| UNSUPPORTED_ASSIGNOR: int | ||
| UNSUPPORTED_COMPRESSION_TYPE: int | ||
| UNSUPPORTED_ENDPOINT_TYPE: int | ||
| UNSUPPORTED_FOR_MESSAGE_FORMAT: int | ||
| UNSUPPORTED_SASL_MECHANISM: int | ||
| UNSUPPORTED_VERSION: int | ||
| VOTER_NOT_FOUND: int | ||
| _ALL_BROKERS_DOWN: int | ||
| _APPLICATION: int | ||
| _ASSIGNMENT_LOST: int | ||
|
|
@@ -535,6 +552,22 @@ class Consumer: | |
| def memberid(self) -> str: ... | ||
| def set_sasl_credentials(self, username: str, password: str) -> None: ... | ||
|
|
||
| class ShareConsumer: | ||
| """Share Consumer for queue-like message consumption (KIP-932).""" | ||
| @overload | ||
| def __init__(self, config: Dict[str, Any]) -> None: ... | ||
| @overload | ||
| def __init__(self, config: Dict[str, Any], /, **kwargs: Any) -> None: ... | ||
| @overload | ||
| def __init__(self, **config: Any) -> None: ... | ||
| def subscribe(self, topics: List[str]) -> None: ... | ||
| def unsubscribe(self) -> None: ... | ||
| def subscription(self) -> List[str]: ... | ||
| def poll(self, timeout: float = -1) -> List[Message]: ... | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it should be |
||
| def close(self) -> None: ... | ||
| def __enter__(self) -> "ShareConsumer": ... | ||
| def __exit__(self, exc_type: Any, exc_value: Any, exc_traceback: Any) -> Optional[bool]: ... | ||
|
|
||
| class _AdminClientImpl: | ||
| def __init__(self, config: Dict[str, Union[str, int, float, bool]]) -> None: ... | ||
| def __enter__(self) -> Self: ... | ||
|
|
||
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.