Open redboltz opened 5 years ago
In addition mqtt_cpp has https://github.com/redboltz/mqtt_cpp/wiki/Persistence functionality. If the publish message should be stored, then call persistent handler. This functionality should be integrated well with offline message storing.
I discussed offline message storing before. I searched issues but not found. Maybe the discussion is held at the comment on the some PR.
So let me explain what is the difficult point to support offline messaging. I've checked MQTT.js and paho(Java). And I sent some PRs to MQTT.js and merged. paho's offline publish doesn't work well, so far.
The problem seems to be not well recognized.
What is offline message storing
When the client is not connected to the broker, user can send message and the message is stored somewhare. The situation happens before the first connection and after disconnection.
Difficlut point
You may think that the solution is simple, just store the messages to the queue. Unfortunately, it is not so simple.
Consider the following scenario:
It is not offline message sending. Just resending.
How about the following scenario:
This is https://github.com/redboltz/mqtt_cpp/wiki/Offline-Publish currently supported. Publish at the step1 is considered "send message but not received puback" message. I think that it is reasonable.
Consider
In this case, publish at step3 is offline publish. Step2 disconnection might happen from the broker side. So we can't recognize the publish message is offline publish or sent online but puback is not received message. The expected behavior is both message should be resent. So we can treat them as the same type of message. *1
Let's consider expanded (not implemented) offline message storing functionality.
The important point is publish message is send before subscribe message. Because publish but puback not received message should be resent just after connack is received. It is defined by MQTT spec. If Step 1 and 2 set the same topic, then the message is not delivered because . It is expected behavior. So we can't use the simple queue.
Possible implementation I just come up with is if the message is publish with QoS1/2, then use existing store mechanism. Otherwise insert newly added queue. The problem is publish with QoS0. Publish order interleaving seems to wrong.
This is difficulty.