Disconnection with inflight queue not empty

49 views
Skip to first unread message

Paolo Patierno

unread,
Mar 19, 2014, 9:28:34 AM3/19/14
to mq...@googlegroups.com
Hello,
I have a doubt on the following question (asked me by a user of my M2Mqtt client library).
With latest version of my library, I have implemented inflight queue and asynchronous publish operation so that the Publish() method put the message into inflight queue and return immediately to the caller.
If I have a sequence like this :

client.Publish(....);
client.Disconnect();

The actual source code inside Disconnect close connection and messages inside inflight queue are lost if they aren't sent yet.
What could be the right behavior ?

The disconnect could wait for publishing of messages but if the network connection is bad, there are attempts and delays between them to resend messages. In this case disconnection is delayed (for seconds, for minutes ... depends on how many messages are in the inflight queue).
Could be it the right solution ?
Or a requested disconnection must to be executed immediately and the messages inside inflight queue are lost ?

Paolo.

Jeff McKelvey

unread,
Mar 19, 2014, 3:54:16 PM3/19/14
to mq...@googlegroups.com
Paolo,

Is there any way the user of the API knows whether or not the Publish has completed? For example through a callback or event? If so, my thought is that you leave it up to the user of the API. They can wait for the publish completion then call Disconnect, or they can ignore the publish completion and call Disconnect immediately in which case they would loose any inflight data. Just my 2 cents.

Jeff

Paolo Patierno

unread,
Mar 19, 2014, 4:05:42 PM3/19/14
to mq...@googlegroups.com
Hi Jeff,
this is the explanation I gave to the user who contacted me.
I explained him that the user application has the role to understand if it is important or not to disconnect before inflight messages are published. My library raises an event for every published message and the user can execute disconnect inside that event.
I understood that he did't like this solution.

Paolo

Reply all
Reply to author
Forward
0 new messages