Eclipse Paho MQTT:在 Python 客户端中禁用消息的离线缓冲

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

this page 所述,Eclipse Paho Python 客户端为客户端离线时未发送的消息提供缓冲区,这些消息最终在客户端重新连接到代理时发送。

有没有办法禁用此功能以防止大量客户端同时重新连接时服务器泛洪?

调用reinitialise()方法将清除存储的消息。

来自文档 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.

重新初始化的文档在这里:

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()

您可以将其设置为在 on_disconnect 回调中调用。