paho.mqtt.javascript
paho.mqtt.javascript copied to clipboard
DeliveryToken for Paho MQTT Javascript client
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.
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."); }
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?
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
Thanks a lot @miketran78727
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)