I am learning MQTT in python and the protocol for QOS = 1 and 2. I'm concerned about my Raspberry Pi getting too bogged down, or if there are other unexpected problems at the server. I can see there are limits for queued and inflight messages as shown below.

So far I haven't been able to read about or understand what happens to my newest published message if these queues hit either of their limits. I would guess that the newest message gets top treatment and the oldest are dropped when a limit is reached, but I can't find that stated explicitly.

Is that in fact what will happen?

"Bonus points:" Is there a way to learn which Message IDs are still held in the queue?


import paho.mqtt.client as mqtt
client = mqtt.Client("I am your client")

Reading about qos 1 and 2 help(client.max_queued_messages_set) yields

Set the maximum number of messages in the outgoing message queue. 0 means unlimited.

and

help(client.max_inflight_messages_set) yields

Set the maximum number of messages with QoS>0 that can be part way through their network flow at once. Defaults to 20.

The code that handles the max_queued_messages is here

if self._max_queued_messages > 0 and len(self._out_messages) >= self._max_queued_messages:
    message.info.rc = MQTT_ERR_QUEUE_SIZE
    return message.info

This looks like it does not bump any messages out of the queue and the it is up to you to handle storing this new message if you still want to keep it.

The code for the max_inflight_messages is here.

This will queue a message if there are currently too many inflight messages.

Since the message queue test is done first there will always be room to queue the new message if the inflight limit is hit.

  • Thanks for your speedy answer! It's late here so I'll have a go in the morning. It sounds like this could be a problem if I wanted the most recent message to have "top priority" though I'm not sure what that means yet, so I will give the code in your links a thorough looking-at. – uhoh Nov 21 at 16:52

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.