AsyncAPI#
FastStream generates an AsyncAPI document of the service.
from faststream import FastStream
from faststream_sqs_sns import CapoSqsBroker, RedrivePolicy, SnsTopic, SqsQueue
broker = CapoSqsBroker(
region="eu-central-1",
description="Orders of the shop",
)
app = FastStream(broker)
shipments = broker.publisher("shipments", description="Orders ready to ship")
events = broker.publisher(SnsTopic("events"), description="Order events")
@broker.subscriber(
SqsQueue(
"orders-billing",
visibility_timeout=60,
redrive=RedrivePolicy("orders-dead", max_receive_count=5),
),
topic=SnsTopic("orders"),
description="Bills an order",
)
@shipments
async def bill(order: dict[str, int]) -> dict[str, int]:
return {"order_id": order["id"]}
A subscriber is a channel at its queue name, with the SQS channel binding: name, fifoQueue,
visibilityTimeout when set, receiveMessageWaitTime and, for a queue with a redrive policy,
the dead-letter queue and maxReceiveCount. A publisher of a queue has the same channel and an
SQS operation binding. A publisher of a topic is a channel at the topic name with the description
SNS topic <name>, and a subscriber with topic= names its topic in its description.
Serve the document in the browser:
faststream docs serve service:app
Write it to a file:
faststream docs gen service:app
title, description and include_in_schema of subscribers and publishers set the text of the
operations. The broker's description, tags, specification_url and protocol set the
server entry. Without specification_url the server is endpoint_url, or
https://sqs.<region>.amazonaws.com.
With AwsSecurity the document describes a userPassword scheme: an AWS access key pair signed
with Signature Version 4. It never contains the key itself.