Ali Khan
Ali Khan

Reputation: 134

How to store messages in /mosquitto/data MQTT mosquitto?

I am running Docker in AWS ECS and inside the docker container in ECS instance i am running eclipse-mosquitto

I need to store the messages in /mosquitto/data

What i tried

docker exec -it [container name] sh navigated to /mosquitto/config/mosquitto.conf

Modified the mosquitto.conf file and added these lines :

persistence true
persistence_location /mosquitto/data/
listener 1883
listener 9001
protocol websockets

NOTE

I have mounted EFS on /mosquitto so i expect the configuration file to persist and i expect it to use that configuration file next time the container restarts

What i expect

Whenever i am publishing/subscribing to a topic it should store the relevant data under mosquitto/data

Upvotes: 0

Views: 1779

Answers (1)

hardillb
hardillb

Reputation: 59816

First

Logging into a running container and editing the config file won't change the running brokers behaviour.

You would normally need to restart the container (which will revert the changes to the config file)

You can mount your own config file into the container at start time with the following command line option (described on the docker hub page)

$ docker run -it -p 1883:1883 -p 9001:9001 -v mosquitto.conf:/mosquitto/config/mosquitto.conf eclipse-mosquitto

Secondly

mosquitto will not store all messages in the persistence file, that is not what it's for. The file is only used to store QOS 1 or 2 messages that are in flight and retained messages. These messages are normally kept in memory, but are written to the file at regular intervals or at broker shutdown so they can be restored when the broker restarts. Also the format of the persistence file is a custom binary format, it's not something you can easily read.

Upvotes: 2

Related Questions