0

Is it possible to get the retained payload for a topic on the mosquitto server without actually subscribing to it?

I want to write a program which will run on the same server as mosquitto, and be able to get the retained payload on certain topics, without actually subscribing to these topics.

I want to know if it is possible to access mosquitto's internal data (in a version-agnostic way) to accomplish this.

Shoaib Ahmed
  • 424
  • 2
  • 9
  • 1
    Why do you want to do this? What benefit is there over just subscribing to the topic? – hardillb Jun 08 '16 at 10:16
  • Possible duplicate of [how to read MQTT mosquitto server persisted DB file](http://stackoverflow.com/questions/31943759/how-to-read-mqtt-mosquitto-server-persisted-db-file) – hardillb Jun 08 '16 at 10:21
  • This program I'm writing is a server designed to follow a request-response pattern for communication. Subscribing to these topics and waiting for their response elsewhere (due to the async nature of my client library) and synchronising all of this in the end will require some major redesigning, especially because I want the program to scale well. – Shoaib Ahmed Jun 08 '16 at 10:30
  • 1
    That doesn't really explain why you want to read the values without subscribing and as pointed out in my answer, subscribing is the only way to get consistent answers – hardillb Jun 08 '16 at 10:35
  • 1
    You've got the mosquitto code, you can change it to do what you want. – ralight Jun 08 '16 at 11:16

1 Answers1

1

The only way to do this would be to read the mosquitto persistence database.

This file is not meant to be read by anything other than the broker it's self but you could look at the code in the broker/libmosquitto to get the format.

Also it may not always be accurate depending on how often you have configured mosquitto to flush it's state to the database. Look at the autosave_interval and autosave_on_change config options.

Also look at how to read MQTT mosquitto server persisted DB file and Read .db file in Mosquitto

Community
  • 1
  • 1
hardillb
  • 54,545
  • 11
  • 67
  • 105