Skip to content

In-Progress sender#

NATS JetStream uses the at-least-once principle, so the message will be redelivered until it receives the ACK status (even if your handler takes a long time to process the message). You can extend the message processing time with an in-progress request.

Full Example
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
import asyncio

from faststream import Depends, FastStream
from faststream.nats import NatsBroker, NatsMessage

broker = NatsBroker()
app = FastStream(broker)

async def progress_sender(message: NatsMessage):
    async def in_progress_task():
        while True:
            await asyncio.sleep(10.0)
            await message.in_progress()

    task = asyncio.create_task(in_progress_task())
    yield
    task.cancel()

@broker.subscriber("test", dependencies=[Depends(progress_sender)])
async def handler():
    await asyncio.sleep(20.0)