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

Add new callback called when message is put into outgoingStore. #869

Merged
merged 2 commits into from Sep 18, 2018

Conversation

ogis-fujiwara
Copy link
Contributor

Added new callback cbStorePut to publish(). cbStorePut is called when message is put into outgoingStore.

Problem:
When disconnection occures right after publish() but callback is not called, then reconnect, client can't know if the message is completely stored into outgoingStore.

Outcome:
This commit fixes above problem.
Client can know that message has been put into outgoingStore when cbStorePut is called.

Added new callback `cbStorePut` to `publish()`. `cbStorePut` is called when message is put into `outgoingStore`.

Problem:
When disconnection occures right after `publish()` but `callback` is not called, then reconnect, client can't know if the message is completely stored into `outgoingStore`.

Outcome:
This commit fixes above problem.
Client can know that message has been put into `outgoingStore` when `cbStorePut` is called.
@ogis-fujiwara
Copy link
Contributor Author

Motivation:
We have a requirement as below.
Client application using MQTT.js needs to shutdown after it receives puback, if the app is requested to shutdown from user while it is waiting puback after publish.
But if the app can't receives puback soon because broker is busy (or network is slow), the app can shutdown if it is sure that the message is put into outgoingStore. This is because the app can restore message from outgoingStore on persistence store e.g., mqtt-level-store when reconnect.
Introduced callback cbStorePut realizes above request.

README.md Outdated
@@ -343,7 +343,7 @@ and connections

-------------------------------------------------------
<a name="publish"></a>
### mqtt.Client#publish(topic, message, [options], [callback])
### mqtt.Client#publish(topic, message, [options], [callback], [cbStorePut])
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would prefer the new callabck to be in the option instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I changed that the callback is one of publish method's options.

Copy link
Member

@mcollina mcollina left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@mcollina mcollina merged commit f94cb75 into mqttjs:master Sep 18, 2018
@ogis-fujiwara
Copy link
Contributor Author

Thank you very much for merging.

@ogis-fujiwara ogis-fujiwara mentioned this pull request Sep 19, 2018
@ogis-fujiwara ogis-fujiwara deleted the cb-store-put branch September 19, 2018 02:04
redboltz pushed a commit to redboltz/MQTT.js that referenced this pull request May 19, 2019
Add new callback called when message is put into `outgoingStore`.
redboltz pushed a commit to redboltz/MQTT.js that referenced this pull request May 19, 2019
Add new callback called when message is put into `outgoingStore`.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants