简体   繁体   中英

Eclipse Paho MQTT : disable offline buffering of messages in Python client

As stated on this page , the Eclipse Paho Python client provides a buffer for messages not sent when the client is offline, these messages are finally sent when the client reconnects to the broker.

Is there a way to disable this feature to prevent server flooding when a large number of clients reconnects at the same time ?

Calling the reinitialise() method will clear stored messages.

From the doc here

clean_session

 a boolean that determines the client type. If True, the broker will remove all information about this client when it disconnects. If 

False, the client is a durable client and subscription information and queued messages will be retained when the client disconnects.

Note that a client will never discard its own outgoing messages on disconnect. Calling connect() or reconnect() will cause the messages to be resent. Use reinitialise() to reset a client to its original state.

Documentation for reinitialise is here:

reinitialise()

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

The reinitialise() function resets the client to its starting state as if it had just been created. It takes the same arguments as the Client() constructor. Example

mqttc.reinitialise()

You can set this up to be called in the on_disconnect call back.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM