Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to cleanly disconnect without losing messages? #749

Open
nneul opened this issue Sep 23, 2023 · 1 comment
Open

How to cleanly disconnect without losing messages? #749

nneul opened this issue Sep 23, 2023 · 1 comment
Labels
Status: Available No one has claimed responsibility for resolving this issue. Status: More info needed More information needed from issue author

Comments

@nneul
Copy link

nneul commented Sep 23, 2023

The main doc page has this notation:

QoS 2 messages which have been received from the Server, but have not been completely acknowledged.

Since the client will blindly acknowledge any PUBCOMP (last message of a QoS 2 transaction), it won't hang but will lost this QoS 2 message.

Is there any example of how to do the equivalent of this pseudocode?

connect
loop_forever
send disconnect (in response to some event/change/external indication) - for testing, just assume a disconnect immediately after first message received. 
process any messages that we have received from server, but not yet processed with on_message

Essentially I just want to "process anything pending in receive queue and then exit".

I have tried max_inflight_messages_set(), but that doesn't appear to change any behavior for received messages.

@github-actions github-actions bot added the Status: Available No one has claimed responsibility for resolving this issue. label Sep 23, 2023
@MattBrittan
Copy link
Contributor

process anything pending in receive queue and then exit

If I'm understanding you correctly then this is not something the MQTT protocol really supports (there is no way to ask the server to send all waiting messages and then disconnect). All you can really do is connect and wait until you believe you have all of the messages (possibly due to a timestamp within the message body, or timing out when, for example, no messages are received in a second).

max_inflight_messages_set() relates to outbound messages (and only relates to the connection between the client and the server).

If the above answers your question then please close off this issue, otherwise please provide further information re your requirements (but, perhaps, stackoverflow might be a better venue as this seems likely to be a protocol question rather than something specific to this library).

@MattBrittan MattBrittan added the Status: More info needed More information needed from issue author label Jan 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Status: Available No one has claimed responsibility for resolving this issue. Status: More info needed More information needed from issue author
Projects
None yet
Development

No branches or pull requests

2 participants