I'm newbie in MQTT. I use mqttTopic.publish(message)
Can I check if the subscriber which subscribed to topic received the message or not?
2 Answers
It depends on your broker implementation.
First, you can ensure your broker received correctly your message by using MQTT Quality of Service :
- 0 means "Fire and Forget"
- 1 means "At least once"
- 2 means "Exactly once"
If you want to ensure your subscriber received your message, you can subscribe to system topics. For example, broker Mosquitto provides $SYS/broker/messages/publish/received
, that is the total number of PUBLISH messages received since the broker started. So you have to verify if your broker implementation has this kind of feature or code it yourself.

- 1,819
- 17
- 25
-
QOS is only ever for a single leg of a transaction (publisher to broker or broker to subscriber), never end to end. Also checking the `$SYS/broker/messages/published/received` count only works if there are only ever 1 subscriber for every message published, this is not a good assumption. – hardillb Jun 27 '18 at 10:27
-
That's exactly what I said about QOS. System topic is only a reflection, not a solution. – victor gallet Jun 27 '18 at 10:32
You can not (at a raw protocol level). There is no end to end delivery notification in MQTT.
There are QOS (Quality of Service) levels are always just between a single client and the broker. This means that if a client publishes a message at QOS 2 then the multi part handshake to ensure the message is only delivered once is just between client and the broker, not any other clients that may be subscribed to the topic (at any QOS level).
It is important to remember that part of point of using a pub/sub system is to decouple the producer (publisher) of information from those consuming (subscriber). When a message is published there may be any where from 0 to an infinite number of subscribers.
If you need end to end delivery notification then you need to include a message id in the payload of the message and then publish a second message from the subscribed client with that id in so the publisher can see that it has been received.

- 54,545
- 11
- 67
- 105