Reputation: 1114
I am using the current version of Paho MQTT android client,( compile org.eclipse.paho:org.eclipse.paho.client.mqttv3:1.1.0
) and I am trying to get the message ID from every message received from the messageArrived()
callback. This is how I am doing it.
@Override
public void messageArrived(String topic, MqttMessage message) throws Exception {
String plainMessage = new String(message.getPayload());
int messageID= new Integer(message.getId());
System.out.println(messageID);
}
Update
With a QoS
of 2
The message ID returns Zero anytime the message arrives or the method messageArrived is called.
Please does anybody has any ideas as to how to resolve this?
Upvotes: 0
Views: 1765
Reputation: 7293
I am not familiar with Paho, but supposing that "message id" is the same thing as "packet identifier" being talked about in MQTT spec: it's not an unique numbering sequence for all of your messages. It's just two bytes (so it probably is the same thing because Paho is using the smallest primitive type capable of holding two bytes unsigned). It's meant to match multiple messages in flight during the multi stage handshake of QoS>0. So my theory is this: whatever MQTT broker you are attaching to, it's using this limited sequence sparsely. It may show nonzero numbers only when there is multiple messages in flight. Which you should be capable of testing simply, if i read Paho javadoc right: keep firing messages but hold returning from messageArrived
.
Try it and let me know. I'm speculating a little bit. If i speculate some more, that you wanted to use this message id as your application-level unique identifier of all your messages: this is not the right tool. You must provide your own sequence on application level.
Upvotes: 2