I'm trying to build an instant-messaging app using MQTT. But I've hit a road block as I'm not able to receive all messages sent by the publisher when the client reconnects after going offline for some time. The client is connected to the broker with these settings:
- A client id
- clean session - false
- receive with QoS 2
While the publisher sends messages with these settings:
- QoS 2
- retain flag set to true
The problem is when the client reconnects, it receives only the latest (offline) message sent by the publisher while all the preceding messages are lost.
I was going through some articles where it is mentioned that the persistent connection means that the broker persists the topic subscriptions and all the QoS 1 and 2 messages. Here are some of them: HiveMQ persistent connections, another article.
Is there a workaround wherein I can get all the messages published on a topic while the client was offline or I am doing something wrong?
P.S. I've gone through this Receive offline messages mqtt link already and I'm doing the same as answered but it doesn't solve my issue.