-
Hi, This is the code: import os
from contextlib import asynccontextmanager
from typing import AsyncIterator, TypedDict
from django.core.asgi import get_asgi_application
from starlette.applications import Starlette
from starlette.routing import Mount
from faststream.rabbit import RabbitBroker
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "app.settings")
broker = RabbitBroker()
@asynccontextmanager
async def broker_lifespan(app):
await broker.start()
try:
yield
finally:
await broker.close()
app = Starlette(
routes=(
Mount("/", get_asgi_application()),
),
lifespan=broker_lifespan,
) This works ok and the process establishes the connection to RabbitMq. Thanks in advance! |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
@ognjenk |
Beta Was this translation helpful? Give feedback.
-
Ah perfect, somehow missed that answer! |
Beta Was this translation helpful? Give feedback.
@ognjenk
I happy, that FastStream is helpful for you!
I think, the answer on your question can be found in #854 discussion
There you can find a little code snippet to make a broker syncify wrapper. This way you can easily publish messages from django sync code.