ReceivingΒΆ
Receiving messages is handled by the @app.channel(name) decorator.
from asyncfast import AsyncFast
from pydantic import BaseModel
app = AsyncFast()
class Payload(BaseModel):
id: str
name: str
@app.channel("channel")
async def handle_channel(payload: Payload) -> None:
print(payload)
{
"asyncapi": "3.0.0",
"info": {
"title": "AsyncFast",
"version": "0.1.0"
},
"channels": {
"HandleChannel": {
"address": "channel",
"messages": {
"HandleChannelMessage": {
"$ref": "#/components/messages/HandleChannelMessage"
}
}
}
},
"operations": {
"receiveHandleChannel": {
"action": "receive",
"channel": {
"$ref": "#/channels/HandleChannel"
}
}
},
"components": {
"messages": {
"HandleChannelMessage": {
"payload": {
"$ref": "#/components/schemas/Payload"
}
}
},
"schemas": {
"Payload": {
"properties": {
"id": {
"title": "Id",
"type": "string"
},
"name": {
"title": "Name",
"type": "string"
}
},
"required": [
"id",
"name"
],
"title": "Payload",
"type": "object"
}
}
}
}
You can process and parse the payload, parameters, and headers of a message.