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.