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

Added removeOutgoingStore function. #658

Merged
merged 5 commits into from
Jul 31, 2017

Conversation

redboltz
Copy link
Contributor

I'd like to have removing a message from outgoing store functionality. I connect a MQTT broker using MQTT.js. The broker have permission control functionality. That means a client can publish only if the client have permission. The permission is defined a pair of ClientId (or Username) and topic.
Permission management is out of scope of MQTT spec, but there are some brokers that support it.

When I publish QoS1 message to a topic that is not permitted, then the broker doesn't return puback because the message is not processed. Some brokers immediately disconnect, but other brokers keep connection and report errors using some special topic like $SYS/error_reporpt by publish back.

I'm using a latter type broker. After the client received the error, I'd like to remove in-flight publish message. Because it still consuming packet id. In addition, when the client disconnect and connect again, the client will resend the message, and will get the same error.

So I'd like to remove the message.

I implement the function and tests. If it has some problem, I will improve my pull request.

@codecov
Copy link

codecov bot commented Jul 29, 2017

Codecov Report

Merging #658 into master will increase coverage by 0.06%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #658      +/-   ##
==========================================
+ Coverage   93.16%   93.22%   +0.06%     
==========================================
  Files           8        8              
  Lines         658      664       +6     
  Branches      160      160              
==========================================
+ Hits          613      619       +6     
  Misses         45       45
Impacted Files Coverage Δ
lib/client.js 96.27% <100%> (+0.05%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update bdebe51...4988a48. Read the comment docs.

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.

Can you please update the docs as well?

lib/store.js Outdated
Store.prototype.delByMessageId = function (messageId) {
delete this._inflights[messageId]
return this
}
Copy link
Member

Choose a reason for hiding this comment

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

This new method is not needed, you can use https://github.com/redboltz/MQTT.js/blob/c35e0a615b44bb235fecffb6b2ae8bdee4556c5a/lib/store.js#L74 and call it with { messageId }.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If I use del, and matches messageId, undefined cb seems to be called.

https://github.com/redboltz/MQTT.js/blob/c35e0a615b44bb235fecffb6b2ae8bdee4556c5a/lib/store.js#L77

Can I update del as follows?

Before

    cb(null, packet)

After

    if (cb) {
      cb(null, packet)
    }

Copy link
Member

Choose a reason for hiding this comment

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

you can pass nop to del.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks, I updated it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

nodejs 7 and 8 reports an error on travis-ci. I updated { messageId } to { messageId: mid}, and changed the parameter name to mid.

@redboltz
Copy link
Contributor Author

Thank you for the comment.

Can you please update the docs as well?

Do you mean README.md? I will do that soon.

@mcollina
Copy link
Member

Yes, README.md.

Removed `delByMessageId` and use `del`.
@redboltz
Copy link
Contributor Author

I added README.md.

lib/client.js Outdated
* @example client.removeOutgoingStore(client.getLastMessageId());
*/
MqttClient.prototype.removeOutgoingStore = function (messageId) {
delete this.outgoing[messageId]
Copy link
Member

Choose a reason for hiding this comment

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

maybe we should call the callback store in this object with an Error.

lib/client.js Outdated
* @example client.removeOutgoingStore(client.getLastMessageId());
*/
MqttClient.prototype.removeOutgoingStore = function (mid) {
delete this.outgoing[mid]
Copy link
Member

Choose a reason for hiding this comment

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

Maybe we should call the outgoing callback (if exists) with an error?

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 agree. It is better to inform the client the result. I updated the code, test, and document.

lib/client.js Outdated
*
* @example client.removeOutgoingStore(client.getLastMessageId());
*/
MqttClient.prototype.removeOutgoingStore = function (mid) {
Copy link
Member

Choose a reason for hiding this comment

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

the name could be a bit more meaningful, something like removeOutgoingMessage.

@mcollina mcollina merged commit 374667d into mqttjs:master Jul 31, 2017
@redboltz
Copy link
Contributor Author

Thank you very much!

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.

2 participants