Closed andreaimprovised closed 2 months ago
Hello @andreaimprovised,
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.confluent import KafkaBroker
from faststream.confluent.annotations import (
KafkaMessage,
Logger
)
import json
import asyncio
broker = KafkaBroker("localhost:9092")
topic = "confluent-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
Retries do not work for the confluent-kafka library as far as I can tell.
Seems related to https://github.com/airtai/faststream/issues/1001 in some way.
How to reproduce
Include source code:
And/Or steps to reproduce the behavior:
Expected behavior I expect the "hello" message to be processed 4 times. The first three times should raise the exception, and the 4th should succeed. I then expect the "hi" message to be processed without exception.
Observed behavior The "hello" message is processed once and raises an exception. Then the "hi" message is processed once without exception.
This is my console output (I forgot to run step (3) for this run)
Screenshots Not much else to share.
Environment Running FastStream 0.5.5 with CPython 3.11.8 on Darwin
Additional context
This seems to be a workaround if I do it right before I raise the exception: