Instead of keeping messages, which could not be sent during a connection loss, persist them in a file or sqllite database.