Search code examples
queuestoremqttmosquitto

Keeping a series of messages in an MQTT Topic


I'm not sure if this is possible or not. If I set a number of messages to be persisted under a topic for some period of time, can I later grab all of them?

I have an MQTT Broker (Mosquitto) set up already for communication between my services but I now also need some storage for several messages, ideally keeping the last 24 hours worth of messages and being able to pull them out later.


Solution

  • Message persistence is only for clients that have subscribed but are currently disconnected and when they do reconnect do so with the cleanSession flag set to false. In which case all the messages published while that client was disconnected.

    You can not use a MQTT broker to store an arbitrary number of messages and retrieve them later. If a client is connected then all messages for it's collection of subscribed topics will be delivered as soon as possible.

    If you want to log messages for later you will have to implement this separately, there are plenty of examples of applications that store messages in databases available