fastapi-mqtt
fastapi-mqtt copied to clipboard
Pass MQTT client to a router
Hi,
I would like to know if it is possible to pass the MQTT client initiated by init_app() to a router that is included by included_router()?
mqtt_config = MQTTConfig()
mqtt = FastMQTT(
config=mqtt_config
)
app = FastAPI()
mqtt.init_app(app)
app.include_router(activities.router)
I would like to access the @mqtt.on_message() decorator from the activities.router routes to read the message only when a specific route is called.
Thanks for your help.