fastapi-mqtt icon indicating copy to clipboard operation
fastapi-mqtt copied to clipboard

Pass MQTT client to a router

Open goldyfruit opened this issue 3 years ago • 0 comments

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.

goldyfruit avatar Jun 29 '22 19:06 goldyfruit