Closed dem214 closed 2 months ago
Your example is inherently flawed because you are specifying two different topics for the same consumer group. Use a single topic for one consumer group.
Seems like you are using Kafka in a wrong way and this problem does not related to FastStream iself. Please, reopen the Issue if you don't agree
Is there a problem to use one consumer group ID for several Kafka topics? I didn't find any restrictions in the Kafka architecture or its documentation. If you have any other information, please let me know.
Is there a problem to use one consumer group ID for several Kafka topics? I didn't find any restrictions in the Kafka architecture or its documentation. If you have any other information, please let me know.
This looks like an issue with aiokafka
rather than an issue with FastStream
or a restriction from Kafka. There are multiple issues from multiple time period indicating the same issue in aiokafka
- https://github.com/aio-libs/aiokafka/issues/880, https://github.com/aio-libs/aiokafka/issues/575, https://github.com/aio-libs/aiokafka/issues/727.
@dem214 The example you have mentioned works with confluent-kafka
library without any change.
import asyncio
import logging
from faststream import FastStream
# import from faststream.confluent instead of faststream.kafka
from faststream.confluent import KafkaRouter, TopicPartition, KafkaBroker
router = KafkaRouter()
@router.subscriber(
't1',
group_id='cg1',
)
async def handle_group(msg):
print('handle_group')
@router.subscriber(
group_id='cg1',
partitions=[TopicPartition('t2', 0), TopicPartition('t2', 1)]
)
async def handle_partition(msg):
print('handle_partition')
broker = KafkaBroker(
log_level=logging.INFO,
graceful_timeout=5.0,
)
broker.include_router(router, prefix='rtr_')
app = FastStream(broker)
# Added to publish a message to topics rtr_t1 and rtr_t2
@app.after_startup
async def publish_msgs() -> None:
async def _publish_msgs() -> None:
await asyncio.sleep(5)
print("Publishing messages")
await broker.publish({"name": "Alice"}, topic="rtr_t1")
await broker.publish({"name": "Bob"}, topic="rtr_t2")
asyncio.create_task(_publish_msgs())
If you need the behaviour you have mentioned, you could use confluent-kafka
instead of aiokafka
.
Describe the bug When subscribing to a topic through a coordinator and to partitions directly using one
group_id
, an error occurs, making consuming of messages is imposible.How to reproduce Include source code:
And/Or steps to reproduce the behavior:
Expected behavior Works fine and consume messages from both topics
Observed behavior Got an error in logs:
Environment Running FastStream 0.5.14 with CPython 3.11.4 on Linux