Reputation: 2058
Is it possible to configure a set of default/hardcoded retained messages to be available on MQTT when Mosquitto starts up?
I would like to use retained messages for app configuration in a microservice architecture to allow modifying and distributing configuration values on runtime. But I need a way of initializing the message when the app is started for the first time.
Another solution would be an application that checks for the existence of the message on startup, publishing the default message if missing, but this is not possible with MQTT since there is no GET
or EXISTS
operation. A workaround would be to SUBSCRIBE
and wait a few seconds before publishing the default message if no callback has been received, which does not seem to be a reliable solution.
Upvotes: 0
Views: 395
Reputation: 59816
As long as you have enabled persistence and a persistence file, in the mosquitto.conf, to store the data in then any retained messages will still be delivered after a broker restart.
As long as you don't clear the retained messages (by publishing a message on the same topic with the retained bit set and a null payload) then they will always be there.
Upvotes: 1