moquette-io / moquette

Java MQTT lightweight broker
http://moquette-io.github.io/moquette/
Apache License 2.0
2.31k stars 818 forks source link

Duplicate subscription #477

Closed BigGitWorld closed 5 years ago

BigGitWorld commented 5 years ago

Expected behavior

I have a phone client that is possible connect to and disconnect from the server several times. Also my phone client has to subscribe to several topics always and keep this subscription when is connected to the moquette server, so that its very important to DO NOT MISS any payload (of subscribed topics) from the server. I subscribe my phone to my desired topics only at the first time connection to the server and set "clean session" to "false".

Now I suspect in choosing one of these two below scenarios : (1) Is the above behavior sufficient to keep track phone's subscription to that topics even if any server or phone is restarted? (2)Or do I have to subscribe phone to that topics every time that phone is connected again ?

Steps to reproduce

(1) connect phone to the server by "clean session=false" and qos=1. (2) subscribe phone to the server once is connected to the server at the first time.

Moquette MQTT version

Latest version

JVM version (e.g. java -version)

java 1.8

OS version (e.g. uname -a)

Ubuntu 16.04

andsel commented 5 years ago

@BigGitWorld you could open here issue related to Moquette, for example Moquette's inconsistencies respect to MQTT protocol specification or Moquette bugs. It's not intended as question and answer to MQTT protocol. I could suggest you to read the specification. Regards

BigGitWorld commented 5 years ago

@andsel You are right. I have explained my scenario useless, but my question is related to moquette not MQTT protocol spec. My Question : if a client subscribe several time to a same topic, do moquette implementation add that topic several time to List or replace new instead of old one? I ask this question, because my server has minimal RAM and I don't want to consume it by mistake. Regard

andsel commented 5 years ago

If it's same topicFilter than it doesn't create multiple sub (if it does, probably it's a bug in Moquette, and please create test that manifest it and open a bug), if it subscribe to topicFilter that one is a superset of the other then creates 2 subscriptions (example /tennis/# and /tennis/player are 2 different topic filters)

BigGitWorld commented 5 years ago

I'll certainly check this out. In moquette old versions, we could get List<Subscription> by using io.moquette.broker.Server instance : But you have disabled it in version 0.12.1. So how can I get List in moquette version 0.12.1? Do I have to use ISubscriptionsRepository interface?

andsel commented 5 years ago

I removed that method, because from a perspective of client libraries that uses Moquette in embedded mode, it's not a good decision to let them have access to the internal state of the broker, so I thought about something based on the concept of observer or interceptor (to track subscribe/unsubscribe) because asking the full list list of subscriptions could potentially be expensive. I would like to know which is the client's behaviour and which is the information they need from Moquette and what they do with that. I'm open to proposal and suggestions.

BigGitWorld commented 5 years ago

Using "observer - interceptor" concept is a good idea. I think you should enable database options to let server to save subscriptions in a table for example. because I just needed to showList<Subscriptions>to our clients in a project to enable them to modify it.

BigGitWorld commented 5 years ago

By using debug mode, I observed that MemorySubscriptionsRepository class add subscription requests without checking that are duplicated or new.