moscajs / mosca

MQTT broker as a module
mosca.io
3.2k stars 513 forks source link

Broker should store also subscriptions with QoS 0 #693

Closed mitsos1os closed 6 years ago

mitsos1os commented 6 years ago

According to documentation found throughout the internet, there are two separate things to store in the broker when clients uses persistent connection. The messages and the subscriptions of the client. However even though the messages have to be send with QoS > 0 in order to be persisted, the subscriptions should be directly persisted when clean flag is false as stated in https://www.hivemq.com/blog/mqtt-essentials-part-7-persistent-session-queuing-messages in So what will be stored in the session? section

But this is not the case here, because every persistence factory used in mosca, in storeSubscriptions function, explicitly filters out subscriptions with QoS <= 0. Like here This also occurs in other factories...

So for example this has conflicts with the case where I actually do not want any messages to be persisted (sent with QoS 0) but there should be no need to re subscribe the client for every reconnect to the topics that accept these messages...

mcollina commented 6 years ago

This is very likely a won't fix situation.

https://github.com/mcollina/aedes should be more conformant to the spec. Use that one.

mitsos1os commented 6 years ago

I am willing to submit a pull request for that... But could you please tell me what is the state of the aedes project? Is it stable and fully compatible with Mosca? Because I do not see any migration guide?

mcollina commented 6 years ago

Of course, a PR is welcome.

Aedes is more performant than Mosca, and in some cases more stable than Mosca. It's not 100% API compatible, but the approach is similar. All active development happens there, as messing with the internals here is too complicated.

In the future, aedes will be integrated here.

mitsos1os commented 6 years ago

I have just submitted the PR... Could you give me a quick guide (also I believe this should be written to aedes guide), as of how Mosca is (or not) one way compatible with Aedes. So what functionality / API used in mosca is now different in aedes.

mcollina commented 6 years ago

The API is different but you should be able to migrate 1-1.

mitsos1os commented 6 years ago

Please check the Travis buils on the PR. They fail due to MongoDB package signature error.

Also from a quick look into aedes-persistence-mongodb it seems that you also skip restoring of QoS 0 subscriptions... Take a look here

mcollina commented 6 years ago

That is a bug in the aedes mongodb persistence. The “main” one is correct and restores them.