Skip to content

Try using a consumer to query persisted data

In this section, we'll show you how to use a consumer to query persistent data, and we'll show you a demo.

Format in which mqtt messages are stored in ringbus/file

Currently mqtt messages are stored in the form of key/value in ringbus/file, where the key is calculated by hash(key = hash(clientid+topic+id)).

consumer demo

NanoMQ exposes the req/rep interface to allow users to query ringbus data or data that has been dropped from disk.

The NanoMQ repo also provides a consumer demo that you can build and use.

./nng/demo/exchange_consumer/exchange_consumer.c

How to use consumer demo

As mentioned earlier, mqtt messages are stored in the ringbus/file as key/value, so users need to provide the key if they want to query a specific mqtt message.

  1. Get the mqtt messages stored in all files
$ ./demo/exchange_consumer/exchange_consumer "dumpfile"
"{\"file\":[\"61616161616161616161\",\"61616161616161616161\",\"61616161616161616161\",...\"61616161616161616161\"]}"
  1. Get an mqtt message from a file by a specific key
$ ./demo/exchange_consumer/exchange_consumer "dumpkey:5023450830686577130"
"{\"file\":[\"61616161616161616161\"]}"
  1. Get bulk mqtt messages from a file with a specific batch of keys
$ ./demo/exchange_consumer/exchange_consumer "dumpkeys:2062146488009373518,2625100014974548622"
"{\"file\":[\"61616161616161616161\",\"61616161616161616161\"]}"