LiamBindle / MQTT-C

A portable MQTT C client for embedded systems and PCs alike.
https://liambindle.ca/MQTT-C
MIT License
774 stars 275 forks source link

How to know if all pending messages are read #45

Closed horchi closed 5 years ago

horchi commented 5 years ago

after the connection was established I subscribe to "/foo/bar/#" to read all messages (I'am interested in the retained ones - all other I skip at this time). As soon all messages are read I unsubscribe (later on subscribe to a specific topic).

This first step is to build an inventory of all retained messages at any topic below "/foo/bar/#".

Mostly this is working but I have a timing issue, since I don't know how to detect the message consumption is ready ans all messages are read - means published to the callback. I tried to call mqtt_sync but it did not help. The only way I can make shoure I didn't miss one is to subscribe, calling mqtt_sync and then sleep up to 5 seconds. In all other cases some messages where not received.

Is there any way to detect if I got all messages?

Best Regards

LiamBindle commented 5 years ago

So if I understand correctly you are subscribing to a topic and then you want to know when the broker has finished sending all that's topics messages? If so, I don't believe this can be done with MQTT (I could be mistaken though...if anyone knows otherwise please chime in!) because the broker and end-points don't exchange any information regarding what's to come.

Did I understand your question correctly?

horchi commented 5 years ago

Hi, yes that was my point. I'm new to the MQTT protocol stack. In meanwhile I has read some (not really deep) details about it. Yes it seems to be not possible to make sure all pending messages are arrived as on other messaging systems. Therefore feel free to close this here.

Actually I checking some latency and speed issues - I try to implement something what was done before by using system message queues (the IPC resources). The goal is to revoke the host borders given by using the IPC resources. That MQTT cannot reach there speed is clear but actually I got factor ~30-40 I hope I can speed this up a little.

LiamBindle commented 5 years ago

Fair enough. Yeah MQTT will be pretty slow in comparison to a system message queue. Make sure you're calling mqtt_sync(...) very frequently. That's the function that actually does stuff on the network whereas functions like mqtt_publish(...) simply enqueue a message.

Good luck!