1
votes

I am using Python based paho mqtt client to publish data to mosquitto mqtt broker.

Let's assume a scenario, when client wanted to publish message and broker got disconnected.

So python based client object buffers that message in _out_message (Ordered Dictionary), and keep retrying to send messages.

I wanted to know,

  • For how long mqtt client will buffer such message?
  • Is there any time limit or retry limit after which client will drop the message.

I wanted to dump/log such messages.

1
Have you tried looking at the source code?balmy
I have done some level of code walk through, but didn't got any lead on deletion of buffered message? That's why I posted this question?Shivam Seth
@barny, If you have any information on this, Please share your knowledge Or Please guide me to correct forum/place to visitShivam Seth
I have precisely the same level of knowledge as you. The source appears to show: a) the out_messages queue is only used for qos 1,2; and b) no obvious expiry on retries for unacknowledged messages. But feel free to check it yourself. Important for your use of the client to correctly handle on_disconnect() callback and returned values from publish call because the queue is by no means infinite.balmy

1 Answers

1
votes

According to Eclipse Paho Python documentation, you can set the maximum number of outgoing messages with Quality of Service greater than 0 (QoS > 0) that can be pending in the outgoing message queue with the method:

max_queued_messages_set(self, queue_size)

It seems that using the default value (0) all the messages are kept until the MQTT client is able to send them. So, in the end, I suppose that messages are kept until the Python process reach the memory limit imposed by the operating system.

Screenshot taken from Eclipse Paho Python documentation

You can force the MQTT client to discard messages using the method reinitialise.

reinitialise(client_id="", clean_session=True, userdata=None)