Skip to content

Conversation

LeoDJ
Copy link

@LeoDJ LeoDJ commented Jul 26, 2025

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 to get_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.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants