Skip to content
Discussion options

You must be logged in to vote

You don't need taskiq for this. The broker works on its own, so open it in the FastAPI lifespan and publish straight from the endpoint:

from contextlib import asynccontextmanager

from fastapi import FastAPI
from faststream.redis import RedisBroker

broker = RedisBroker("redis://localhost:6379")


@asynccontextmanager
async def lifespan(app: FastAPI):
    async with broker:
        yield


app = FastAPI(lifespan=lifespan)


@app.get("/register")
async def register():
    await broker.publish("john@example.com", channel="send-confirm-email")
    return {"ok": True}

async with broker only connects and disconnects. There's no broker.start() here on purpose. That's the call that launches subs…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
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