I have several QoS2 level messages that cause problems in a scenario when a broker or MQTT client has problems. These problems may include
- the client begins to see server timeouts
- the client has lost contact with the broker (Internet connection down, problem with the broker, ....) for a while and will connect again.
Typically, when an MQTT client begins to receive timeouts or other errors from the broker, the message is stored in a persistent storage (messages in flight) and will eventually be reissued.
However, in the event that the Paho client loses connection with the broker, messages will no longer be considered in flight and will not be stored by Paho. At this point, it seems that the application becomes responsible for maintaining these messages (outside of paho) and re-publishing them.
Am I saying correctly that when the MQTT broker becomes unavailable, the Paho MQTT client cannot help me guarantee that these QoS2 messages will be resent?
So, how can I make a distinction between the following case where client.publish threw a MqttException where Paho did not save the message flow.
Client is currently disconnecting (32102) at org.eclipse.paho.client.mqttv3.internal.ClientComms.shutdownConnection(ClientComms.java:297) at org.eclipse.paho.client.mqttv3.internal.CommsSender.handleRunException(CommsSender.java:154) at org.eclipse.paho.client.mqttv3.internal.CommsSender.run(CommsSender.java:131) at java.lang.Thread.run(Thread.java:745)
And the next in which it is preserved continues the light
Timed out waiting for a response from the server (32000) at org.eclipse.paho.client.mqttv3.internal.Token.waitForCompletion(Token.java:94) at org.eclipse.paho.client.mqttv3.MqttToken.waitForCompletion(MqttToken.java:50) at org.eclipse.paho.client.mqttv3.MqttClient.publish(MqttClient.java:315) at org.eclipse.paho.client.mqttv3.MqttClient.publish(MqttClient.java:307)
Obviously, I can also start doing bookkeeping and save all the inappropriate messages separately, but then I can get duplicates of the QoS level (messages received by both Paho and myself reissued).
How to program the client?
- Do I need to do my own persistence with Paho based on exception codes?
- Do I need to take into account the connectionLost callback and assume that from now on Paho will not be saved for me until the MQTT client recovers?
- Before publishing, I need to check if the client is connected correctly, and assuming that Paho will continue the message?
Here are some exceptions and behavior of Paho's perseverance
- Connection lost (32109): message saved by paho
- The client is currently disconnecting (32102): the message is lost paho
- Server response timeout (32000): message is saved by paho
- Client not connected (32104): message lost paho
What are some of the best practices here with Paho?