-
Notifications
You must be signed in to change notification settings - Fork 179
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add concurrent-between-partitions kafka subscriber (#2017)
* Add concurrent between partitions kafka subscriber * Add warning for unassigned consumers * docs: generate API References * Fix ConcurrentBetweenPartitionsSubscriber logging * docs: generate API References * Add default logging consumer rebalance listener factory * docs: generate API References * Move unassigned consumer warning to rebalance listener * Tweak constructor and tests * Switch to LoggingListenerProxy and return f-strings in logs * docs: generate API References --------- Co-authored-by: Pastukhov Nikita <nikita@pastukhov-dev.ru> Co-authored-by: Arseniy-Popov <Arseniy-Popov@users.noreply.github.com>
- Loading branch information
1 parent
db1033d
commit dfd7b9a
Showing
19 changed files
with
646 additions
and
68 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -178,5 +178,5 @@ | |
} | ||
] | ||
}, | ||
"generated_at": "2025-01-08T14:22:57Z" | ||
"generated_at": "2025-01-10T14:53:01Z" | ||
} |
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
11 changes: 11 additions & 0 deletions
11
docs/docs/en/api/faststream/kafka/listener/LoggingListenerProxy.md
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,11 @@ | ||
--- | ||
# 0.5 - API | ||
# 2 - Release | ||
# 3 - Contributing | ||
# 5 - Template Page | ||
# 10 - Default | ||
search: | ||
boost: 0.5 | ||
--- | ||
|
||
::: faststream.kafka.listener.LoggingListenerProxy |
11 changes: 11 additions & 0 deletions
11
docs/docs/en/api/faststream/kafka/message/KafkaRawMessage.md
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,11 @@ | ||
--- | ||
# 0.5 - API | ||
# 2 - Release | ||
# 3 - Contributing | ||
# 5 - Template Page | ||
# 10 - Default | ||
search: | ||
boost: 0.5 | ||
--- | ||
|
||
::: faststream.kafka.message.KafkaRawMessage |
11 changes: 11 additions & 0 deletions
11
...ream/kafka/subscriber/asyncapi/AsyncAPIConcurrentBetweenPartitionsSubscriber.md
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,11 @@ | ||
--- | ||
# 0.5 - API | ||
# 2 - Release | ||
# 3 - Contributing | ||
# 5 - Template Page | ||
# 10 - Default | ||
search: | ||
boost: 0.5 | ||
--- | ||
|
||
::: faststream.kafka.subscriber.asyncapi.AsyncAPIConcurrentBetweenPartitionsSubscriber |
11 changes: 11 additions & 0 deletions
11
...pi/faststream/kafka/subscriber/usecase/ConcurrentBetweenPartitionsSubscriber.md
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,11 @@ | ||
--- | ||
# 0.5 - API | ||
# 2 - Release | ||
# 3 - Contributing | ||
# 5 - Template Page | ||
# 10 - Default | ||
search: | ||
boost: 0.5 | ||
--- | ||
|
||
::: faststream.kafka.subscriber.usecase.ConcurrentBetweenPartitionsSubscriber |
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,63 @@ | ||
import asyncio | ||
import logging | ||
from typing import TYPE_CHECKING, Optional, Set | ||
|
||
from aiokafka import ConsumerRebalanceListener | ||
|
||
if TYPE_CHECKING: | ||
from aiokafka import AIOKafkaConsumer, TopicPartition | ||
|
||
from faststream.types import AnyDict, LoggerProto | ||
|
||
|
||
class LoggingListenerProxy(ConsumerRebalanceListener): # type: ignore[misc] | ||
"""Logs partition assignments and passes calls to user-supplied listener.""" | ||
|
||
def __init__( | ||
self, | ||
consumer: "AIOKafkaConsumer", | ||
logger: Optional["LoggerProto"], | ||
listener: Optional[ConsumerRebalanceListener], | ||
): | ||
self.consumer = consumer | ||
self.logger = logger | ||
self.listener = listener | ||
|
||
async def on_partitions_revoked(self, revoked: Set["TopicPartition"]) -> None: | ||
if self.listener: | ||
call_result = self.listener.on_partitions_revoked(revoked) | ||
if asyncio.iscoroutine(call_result): | ||
await call_result | ||
|
||
async def on_partitions_assigned(self, assigned: Set["TopicPartition"]) -> None: | ||
self._log( | ||
logging.INFO, | ||
f"Consumer {self.consumer._coordinator.member_id} assigned to partitions: " | ||
f"{assigned}", | ||
) | ||
if not assigned: | ||
self._log( | ||
logging.WARNING, | ||
f"Consumer in group {self.consumer._group_id} has no partition assignments - topics " | ||
f"{self.consumer._subscription.topics} may have fewer partitions than consumers", | ||
) | ||
|
||
if self.listener: | ||
call_result = self.listener.on_partitions_assigned(assigned) | ||
if asyncio.iscoroutine(call_result): | ||
await call_result | ||
|
||
def _log( | ||
self, | ||
log_level: int, | ||
message: str, | ||
extra: Optional["AnyDict"] = None, | ||
exc_info: Optional[Exception] = None, | ||
) -> None: | ||
if self.logger is not None: | ||
self.logger.log( | ||
log_level, | ||
message, | ||
extra=extra, | ||
exc_info=exc_info, | ||
) |
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.