George
George

Reputation: 1114

How to check when a broker has delivered a message to a client(Subscriber)

I am implementing the Paho MQTT Java client for my android project. It is basically an instant messaging system. The publish and subscribe implementation is working very well for me, but I am left with an issue. Subscribed clients are able to receive messages when they are published, however the ability for the system to check when a messaged is received/delivered by the client(subscriber) or not is a bit difficult to implement, this I think its because MQTT does not support that.

Does anybody has an idea as to how to implement this logic in a different way?

Upvotes: 2

Views: 4888

Answers (2)

hardillb
hardillb

Reputation: 59628

The MQTT protocol has no built in End to End delivery notification. There is no way of knowing how many subscribers there is to a topic, it could any where between 0 and many.

If you need End to End delivery notification then you need to build it into your application, by adding a unique id to the payload of each message and then publishing another message (probably on a separate topic) with that id from the client subscribed to the original topic. Messages should also be published and subscribed at QOS 2 to ensure they are only delivered once.

Upvotes: 3

Parth Pandya
Parth Pandya

Reputation: 69

As per the documentation on the MQTT you can set the MqttCallback which has the method deliveryComplete(IMqttDeliveryToken token) now as per the documentation it states that this callback method will be called

when delivery for a message has been completed, and all acknowledgments have been received.

To ensure the delivery set the QoS (Quality of Service) to 2.

If you still have doubts about this approach you can use another approach where you can expect the acknowledgement message from the client on the delivery of the message, however this is just another overhead to the mqtt and it's up to the requirement of yours to use this or not.

You can explore more on their github it also has the sample code to know more about the workings of Mqtt.

I hope this helps

Upvotes: 2

Related Questions