Looking into mqtt as a means to publish messages to browser clients over websockets.
The data would likely be something like a JSON object, whose fields change values over time. I'd like to send over only those changes, not the whole JSON state with each and every message.
Is there a built-in way in the protocol (or some other workaround) that could allow clients to receive a full state on connection, followed by delta-only messages?
One potential workaround would be keeping the full state on a separate topic with retain
flag set, which we'd subscribe to right after the connection establishment, followed by unsub after message is received. But then we'd still be facing the message ordering problem - there's no guarantee the messages on delta topic are following the last state in expected order. Plus there's an overhead of initially subscribing to 2 topics per interested entity instead of one.
No, there is nothing in MQTT that will do this for you.
The best approach is probably to deliver the large payload via HTTP first, then have a topic for each field in the structure and publish updates to each topic. If you include a timestamp with each update, you could timestamp the full data as well, that way you could subscribe to the updates before you download the full object. If you timestamp that as well then you can subscribe to the updates first and apply the required updates once you've got the whole. This would get past the problem of updates while you are downloading the large object.