Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
653 views
in Technique[技术] by (71.8m points)

mqtt - Command to display all delivered messages to a Mosquitto Broker?

I have been using following command to see published messages on the Mosquitto broker:

mosquitto_sub -h IP_ADDRESS -t TOPIC_NAME

However, when I run this command I can see only the recent messages not all published messages. In Mqtt client, I can see messages delivered.

  1. Is there a command to see all messages that were delivered to the broker?
  2. The command only shows messages when we start subscribing?

I have used value 2 for Quality of Service in message properties.

question from:https://stackoverflow.com/questions/65846105/command-to-display-all-delivered-messages-to-a-mosquitto-broker

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

MQTT as a protocol doesn't store all messages, no matter what QOS they were published/subscribed at.

It's also important to remember that QOS is only for one leg at a time. E.g. a message published at QOS2 is ensured to arrive at the broker, but makes no promises about it's delivery to any clients, that is down to what QOS those clients subscribed to the topic at.

MQTT will queue messages for a known client if it has previously subscribed at QOS 1 or 2 and reconnects with the cleanSession flag set to false. This connection needs to exactly the same client id as the previous session.

So if you run the following command:

mosquitto_sub -h [ip addr] -t [topic] -c -i [clientid] -q 2

This will create a persistent session, if you then disconnect (kill mosquitto_sub) when you run the same command again (making sure to keep [clientid] the same the broker will deliver all the messages sent while the client was disconnected. But there is no way to get messages published before the session was established by running the command the first time.

  • -c tells the client to set the cleanSession flag to false.
  • -i [clientid] sets the client id
  • -q 2 sets the subscription QOS to 2

If this is to debug a problem then one possible option would be to ramp up the mosquitto instances logging level then it will log absolutely everything, but this will produce a LOT of output.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...