Skip to content

FastAPI access Context #1039

Answered by Lancetnik
sidjakinsboriss asked this question in Q&A
Dec 12, 2023 · 1 comments · 5 replies
Discussion options

You must be logged in to vote

@sidjakinsboriss we already have the Issue to make FastStream Context FastAPI-compatible

But, for now you can get access to it manually from the context object:

from faststream import context
from faststream.rabbit import RabbitMessage

@router.subscriber("test")
async def handler(msg_body):
    msg: RabbitMessage = context.get_local("message")
    await msg.ack()

Also, if you like the original way to get access to raw message, you can use the following snippet - it works the same way

from typing import Annotated

from fastapi import Depends
from faststream.rabbit.message import RabbitMessage as RawRabbitMessage

def get_msg():
    return context.get_local("message")

RabbitMessage = Anno…

Replies: 1 comment 5 replies

Comment options

You must be logged in to vote
5 replies
@sidjakinsboriss
Comment options

@Lancetnik
Comment options

@Lancetnik
Comment options

@sidjakinsboriss
Comment options

@Lancetnik
Comment options

Answer selected by davorrunje
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants