-
Hi, I just have a question, currently working with faststream and it's great.
I've tried many times to write my custom decorator, but seems like I do something wrong or don't understand something, can you help me with one example. Also I've tried to use Middlewares but it didn't helped me. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
@Amirkaaa hi! Thanks for being with the project To create custom decorator you just need to create the regular one with the 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():
await broker.publish("Hi!", "test") |
Beta Was this translation helpful? Give feedback.
@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 tupesThis is the correct example