-
Notifications
You must be signed in to change notification settings - Fork 159
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add in-progress tutorial to how-to section
- Loading branch information
Showing
3 changed files
with
41 additions
and
0 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
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,39 @@ | ||
--- | ||
# 0.5 - API | ||
# 2 - Release | ||
# 3 - Contributing | ||
# 5 - Template Page | ||
# 10 - Default | ||
search: | ||
boost: 10 | ||
--- | ||
|
||
# In-Progress sender | ||
|
||
Nats Jetstream uses the at least once principle, so the message will be delivered until it receives the ACK status (even if your handler takes a long time to process the message), so you can extend the message processing status with a request | ||
|
||
??? example "Full Example" | ||
```python linenums="1" | ||
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) | ||
|
||
``` |
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