paho.mqtt.javascript icon indicating copy to clipboard operation
paho.mqtt.javascript copied to clipboard

DeliveryToken for Paho MQTT Javascript client

Open ghost opened this issue 9 years ago • 5 comments
trafficstars

Paho MQTT Java client provides MqttDeliveryToken object to track the delivery of the message. But I didn't find any similiar kind of token in Javascript client. My scope is to track the delivery of the different messages. Please help.

ghost avatar Jun 14 '16 10:06 ghost

In Javascript client, you can track the delivery of messages via onMessageDelivered callback, e.g.

client.onMessageDelivered = onMessageDelivered;

function onMessageDelivered(msg) { console.log("onMessageDelivered: " + msg.payloadString + " has been successfully delivered."); }

miketran78727 avatar Jun 14 '16 16:06 miketran78727

Thanks @miketran78727 for the response. But how do I identify the delivery of different messages. Will there be any ID assocaited with the message like DeliveryToken? Or the only way to identify is by comparing the payloadString of the message?

ghost avatar Jun 15 '16 04:06 ghost

Hi @ronaldrandonj You're right. I suggest that we keep this issue open as new feature request.

For now, you can put an identifier in the payload (which is easy to do if you are sending JSON strings) or you can use an array to maintain the inflight messages.

Notes: Qos 0 messages : onMessageDelivered is called immediately if the client is currently connected Qos 1 messages : onMessageDelivered is called when PUBACK is received Qos 2 messages : onMessageDelivered is called when PUBCOMP is received

miketran78727 avatar Jun 15 '16 15:06 miketran78727

Thanks a lot @miketran78727

ghost avatar Jun 15 '16 15:06 ghost

One way that we could track messages is by implementing a similar method to that of the invocationContext in the connect call: http://www.eclipse.org/paho/files/jsdoc/symbols/Paho.MQTT.Client.html#connect

That way you don't need to embed anything in the message itself, you can just look at the context of the message that was delivered (This could be a message ID or something)

jpwsutton avatar Jul 21 '16 13:07 jpwsutton