Gokul M Gokul M - 1 year ago 88
Ruby Question

Acknowledgement on publish - MQTT

How to identify whether the

to a
was success or not. Is there any way to get acknowledgement on publishing to a topic.

If there is any connection loss during
between the clients(Publisher/Subscriber) how to handle it.

I don't want the subscriber to send an ack to specific topic in the publishing end after receiving the pay_load.

Here is my ruby code:

Assume, I have created clients
and configured on both sides.


def publish_it
@client.publish('test/hai', 'message')
# Ack the publish



@client.get do |topic,message|
puts "#{topic}: #{message}"

Answer Source

There is no end to end (publisher to subscriber) delivery notification in MQTT. This is because as a pub/sub protocol there is no way for a publisher to know how many subscribers there are to a given topic, there could be anything from 0 to n.

The QOS levels built into the spec ensure that messages are delivered from the publisher to the broker (and then from the broker to the subscribers). If you want to ensure a message is delivered then use either QOS level 1 or 2.

QOS 1 will ensure a message is delivered at least once (possibly more if there are network problems)

QOS 2 will ensure a message is delivered only once.

In most of MQTT client libraries there is also the deliveryComplete callback which should be called once all the QOS handshake for a publish has been completed, if you add one of these you can be reasonably confident that the message has made it from the publisher as far as the broker. Unfortunately I can't see this implemented in the Ruby client