Caching of unsent messages in case of application shutdown

Hello,
we just implemented a program that uses mqtt to publish data to an mosquitto broker.
As of now, everything is working fine, but I have some concerns about the safety of my data.

The mosquitto library is able to cache messages not sent to the broker because of an offline condition. When the connection is established again, all cached messages are then sent to the broker.
That’s fine.

But what happens, when my application is being closed, and there were cached messages? How can i flush / write them to a persistent storage so that i will be able to sent them at my next program start?

Greetings
Wolfgang

Hi Wolfgang,

I’m afraid it’s not currently possible to write messages to disk from the mosquitto library like you suggest. The queue is persisted in memory only.

Regards,

Roger

Hello Roger,
would it be possible to modify the library on my own to add such a feature? I think I would have to modify mosquitto_publish and the part where the callback fo OnPublished is being called…

Greetings
Wolfgang

Yes you could. My expectation would be that the file persistence would be optional, and that it would also be possible to choose whether only QoS 1 and 2 messages were persisted, or also QoS 0 as well.

Regards,

Roger