-
Notifications
You must be signed in to change notification settings - Fork 73
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Mátyás Kuti
committed
Nov 30, 2023
1 parent
dd9e87e
commit e306273
Showing
16 changed files
with
185 additions
and
130 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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 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,33 @@ | ||
from __future__ import annotations | ||
|
||
from confluent_kafka import Consumer | ||
from confluent_kafka.admin import PartitionMetadata | ||
from confluent_kafka.error import KafkaException | ||
from karapace.kafka.common import _KafkaConfigMixin, KafkaClientParams, raise_from_kafkaexception | ||
from typing import Iterable | ||
from typing_extensions import Unpack | ||
|
||
import secrets | ||
|
||
|
||
class KafkaConsumer(_KafkaConfigMixin, Consumer): | ||
def __init__( | ||
self, | ||
topic: str, | ||
bootstrap_servers: Iterable[str] | str, | ||
verify_connection: bool = True, | ||
**params: Unpack[KafkaClientParams], | ||
) -> None: | ||
if "group_id" not in params: | ||
params["group_id"] = f"karapace-{secrets.token_hex(4)}" | ||
|
||
super().__init__(bootstrap_servers, verify_connection, **params) | ||
|
||
self.subscribe([topic]) | ||
|
||
def partitions_for_topic(self, topic: str) -> dict[int, PartitionMetadata]: | ||
"""Returns all partition metadata for the given topic.""" | ||
try: | ||
return self.list_topics(topic).topics[topic].partitions | ||
except KafkaException as exc: | ||
raise_from_kafkaexception(exc) |
This file contains 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 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
Oops, something went wrong.