Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to retain messages in mqtt if the mosquitto broker goes down?

Tags:

mqtt

mosquitto

I have a scenario wherein the MQTT client publishes a message with a topic . Post this I bring down my mosquitto broker (by killing the process) . When I restart my broker and try consuming the message with the topic , the message is not available . Is there any way I can consume the message which was published before the broker is restarted ?

Note : This is possible if RabbitMQ is used as the messages are stored in the queue . I want to implement the same using MQTT-Mosquitto.

like image 423
shreyas Avatar asked Mar 21 '16 09:03

shreyas


1 Answers

If you enable persistence and specify a directory in your mosquitto.conf file then retained messages will be saved to disk and restored when the broker is restarted.

e.g.

persistence true
persistence_location /path/to/store/data/

Also look at the autosave_interval and autosave_on_changes options in the docs

like image 84
hardillb Avatar answered Jan 01 '23 02:01

hardillb