I want to be able to use the RabbitMQ consumer to listen for new messages but the thread is blocking and the application does not start up. What's the best approach to handling the listening handler asynchronously?
@asynccontextmanager
async def lifespan(app: FastAPI):
client = RabbitMQClient()
await client.connect()
queue_to_callback = {"request.queue": handleRequestNotification}
client.start_consuming(queue_to_callback_dict=queue_to_callback)
client.channel.start_consuming()
yield
await client.close()
In my main.py
:
FastAPI(lifespan=lifespan)
My assumption was async def
was going to make that handler run asynchronously. What's the approach recommended for this and for it to scale to multiple consuming channels?