Implement function to get the amount of buffered messages (incl. QOS 0) #561
+35
−0
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR implements a method to get the amount of buffered messages of the AsyncClient.
This count also includes QOS 0 messages (when
persist_qos0==true
), compared toget_pending_delivery_tokens().size()
.I also tried adding a unit test, but due to my unfamiliarity with the test harness, I didn't find a way to force it to buffer the messages instead of sending them right away and making the test unrealiable.
Because I wanted to display the amount of buffered messages, I had to send QOS 1 messages and use this approach, but I had massive performance problems around a few thousand queued QOS 1 messages on a Raspberry Pi Zero, due to
MQTTAsync_assignMsgId
needing more and more resources to find a free message ID. (Also, I think it would have crashed at around 64k buffered messages anyways, due to running out of IDs).So now I've switched back to QOS 0 messages with
.persist_qos0(true)
, which works fine, but found no currently implemented way to get the buffered count.(Context: I'm using the buffered messages feature for buffering non-critical telemetry data of a vehicle with a WiFi uplink. So it's expected to spend quite some time without a connection to the MQTT broker.
But it should be able to hold 250-500k JSON messages in memory no problem.)