Skip to content

Question, custom decorator #810

Answered by Lancetnik
Amirkaaa asked this question in Q&A
Discussion options

You must be logged in to vote

@Amirkaaa hi! Thanks for being with the project

To create custom decorator you just need to create the regular one with the functools.wraps using to provide FastStream information about the main handler arguments tupes

This is the correct example

from functools import wraps

from faststream import FastStream, Logger
from faststream.nats import NatsBroker


def decorator(func):
    @wraps(func)
    async def wrapper(*args, **kwargs):
        return await func(*args, **kwargs)
    return wrapper


broker = NatsBroker()
app = FastStream(broker)


@broker.subscriber("test")
@decorator
async def handler(msg: str, logger: Logger):
    logger.info(msg)


@app.after_startup
async def test():
    a…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@Lancetnik
Comment options

Answer selected by Lancetnik
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
Converted from issue

This discussion was converted from issue #806 on October 06, 2023 10:08.