-
Notifications
You must be signed in to change notification settings - Fork 174
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
Bug: Event ack'd after calling KafkaMessage.nack
with auto_commit=False
#1001
Comments
Hello @bradydean, Apologies for replying late. |
Interesting... FastStream doen't call |
Seems like with aiokafka >= 0.9 all works fine. All tests at 0.3.5 versions are working correctly, so we can close it, I suppose |
Hi, I'm still experiencing this issue with Faststream 0.47.0. from typing import Any, Dict
from faststream import FastStream
from faststream.kafka import KafkaBroker
from faststream.kafka.annotations import (
KafkaMessage,
Logger
)
broker = KafkaBroker("localhost:9093")
app = FastStream(broker)
@broker.subscriber("source", group_id="foo", auto_commit=False)
async def async_subscriber(message: Dict[str,Any], logger: Logger, msg: KafkaMessage):
logger.info(message)
await msg.nack() # calling this or NOT calling this doesn't change the behavior If I send some messages with for i in $(seq 1 20); do echo "${i}:{\"index\":\"${i}\"}" | kafka-console-producer.sh --bootstrap-server localhost:9093 --topic source --property parse.key=true --property key.separator=:; done I see
I was expecting to consume the same message again and again. Thanks, lorenzo (edit: same behavior if I raise a |
I am not sure, what is it: we creates I have no ideas why it commits the offset anyway. |
@Lancetnik @lorenzobenvenuti |
Thanks @Lancetnik @kumaranvpl . You can reproduce the issue with this application. |
I had a quick look at the code, as far as I can see As a workaround, the consumer can explicitly call @broker.subscriber("source-topic", group_id="foo", auto_commit=False)
async def async_subscriber(body: Dict[str,Any], logger: Logger, msg: KafkaMessage):
logger.info(body)
await msg.nack()
msg.consumer.seek(TopicPartition(msg.raw_message.topic, msg.raw_message.partition), msg.raw_message.offset) |
I think we can just use smth like that: class KafkaMessage:
async def nack(self) -> None:
await self.consumer.seek_to_committed() And it looks correct, but I am not sure about sideeffects or potential problems |
Hello @bradydean, This bug has been fixed as part of https://github.com/airtai/faststream/releases/tag/0.5.18 release. Following is a sample code from typing import Any, Dict
from faststream import FastStream
from faststream.kafka import KafkaBroker
from faststream.kafka.annotations import (
KafkaMessage,
Logger
)
import json
import asyncio
broker = KafkaBroker("localhost:9092")
topic = "kafka-nack-test"
app = FastStream(broker)
@broker.subscriber(topic, group_id="foo", auto_commit=False, auto_offset_reset="earliest")
async def async_subscriber(body: Dict[str,Any], logger: Logger, msg: KafkaMessage):
logger.info(body)
await msg.nack()
@app.after_startup
async def publish_something() -> None:
async def _publish_something() -> None:
i = 10
print(f"Sleeping for {i} seconds")
await asyncio.sleep(i)
message = {"hi": "there"}
await broker.publish(message, topic=topic)
print("Published message" + json.dumps(message))
asyncio.create_task(_publish_something()) |
Describe the bug
Events are ack'd after calling
nack()
.How to reproduce
Expected behavior
After publishing an event to the
test
topic, the message is logged and consumer does not ack the message.Observed behavior
The message is logged and it appears the consumer acks the message. In kafka-ui I see the consumer group is 0 messages behind.
Environment
The text was updated successfully, but these errors were encountered: