Hello,
I have some doubts regarding broker design....
Suppose QoS Level 1...
1. publisher sends PUBLISH message to the broker;
2. broker "store" message and start asynchronous delivery to the subscribers (S1, S2, ... Sn);
3. broker sends PUBACK to the publisher;
At step 2, broker starts to send message to the subscribers. I think that this operation isn't sequential (S1, S2, ...Sn) because in this case for sending message to Si, the broker hast to finish QoS1 handshake with Si-1. I think that the broker can start more threads to send message to the subscribers (not 1 thread for each subscribers but it can use a thread pool to have a minimum of parallelism). In this way each communication with subscriber is independently from the others.
In this case, it is necessary that broker has a queue for each subscriber so in step 2, "store message" means that broker has enqueue the message in all the queue for all the subscribers.
Is it a possible implementation of a broker ? Or has the broker a single queue where it puts the message received ?
When the publisher receives PUBACK, it can send another message. In this case, the broker receives it and enqueue the message as the previous (in each queue for each subscriber). Depending on latency on the network and client status, the trasmission for each subscriber can go ahead with different throughput.
If a client isn't reachable, the broker retry more times. If all attempts goes wrong, has the broker to delete all queued messages from queue related to that client and close connection with the client ?
Obviously, If the client connected with cleansession=false, the broker will persist the message queue before close connection with client.
Suppose QoS Level 2...
Using the same meccanism as previous (a queue for each subscribers). Suppose that the broker sends PUBLISH, receives PUBREC, sends PUBREL but doesn't receive PUBCOMP from client that is connected with cleansession=false. When the client riconnect, it has to restart the entire handshake from PUBLISH or it can assume that client will restart from send the last PUBCOMP. I think that the broker can't do this assumption because the client could not be persistent. Is it right ?
Paolo.