Mosquitto forgets subscriptions that are made on behalf of the client_id (subs made from another process/computer)

Asked by Bardya Momeni

I make subscriptions from another process on another computer ( Server Process ) for a specific client ID, and then I disconnect from the broker and then I try to connect to the broker using the same client ID from another computer (The actual client).
The connection is made successfully from the client, however the subscriptions seem to be forgotten by Mosquitto and the sent messages are not received at all. If I do subscriptions again from the client, I get the messages. ( which I don't want to give ability to the anonymous users to be able to subscribe ).
How can I make mosquitto to remember subscriptions for a specific client ID?
Thank you in advanced.
B. Momeni.

Question information

Language:
English Edit question
Status:
Solved
For:
mosquitto Edit question
Assignee:
No assignee Edit question
Solved by:
Roger Light
Solved:
Last query:
Last reply:

This question was reopened

Revision history for this message
Roger Light (roger.light) said :
#1

Hi,

You need to ensure that the client is connecting with "clean session"
set to false, otherwise the broker does not remember anything for that
client.

You should also ensure that your subscriptions and messages are using QoS>0.

Cheers,

Roger

On Tue, Jul 8, 2014 at 8:32 AM, Bardya Momeni
<email address hidden> wrote:
> New question #251343 on mosquitto:
> https://answers.launchpad.net/mosquitto/+question/251343
>
> I make subscriptions from another process on another computer ( Server Process ) for a specific client ID, and then I disconnect from the broker and then I try to connect to the broker using the same client ID from another computer (The actual client).
> The connection is made successfully from the client, however the subscriptions seem to be forgotten by Mosquitto and the sent messages are not received at all. If I do subscriptions again from the client, I get the messages. ( which I don't want to give ability to the anonymous users to be able to subscribe ).
> How can I make mosquitto to remember subscriptions for a specific client ID?
> Thank you in advanced.
> B. Momeni.
>
>
>
> --
> You received this question notification because you are a member of
> Mosquitto PPA, which is an answer contact for mosquitto.

Revision history for this message
Bardya Momeni (vaskodogama) said :
#2

Thanks Roger Light, that solved my question.

Revision history for this message
Bardya Momeni (vaskodogama) said :
#3

Honestly, we are working on a use case that we want to connect all clients using (CLEAN_SESSION = true) and be sure that the subscriptions won't delete and only stored messages for the clients get deleted.
I read your code and determined that line 142 in context.c deletes the subscriptions for a clean_session client and the next line deletes the messages associated with it. I tried commenting them out but the results failed for my use case.
The question is, how I can delete the messages but keep the subscriptions when clients connect with clean_session?
Thank you Roger...

Revision history for this message
Best Roger Light (roger.light) said :
#4

An easy way to do this with no code modifications would be to just use
QoS 0 with clean session=false. No messages are queued, but
subscriptions are kept.

On Wed, Jul 9, 2014 at 9:21 AM, Bardya Momeni
<email address hidden> wrote:
> Question #251343 on mosquitto changed:
> https://answers.launchpad.net/mosquitto/+question/251343
>
> Status: Solved => Open
>
> Bardya Momeni is still having a problem:
> Honestly, we are working on a use case that we want to connect all clients using (CLEAN_SESSION = true) and be sure that the subscriptions won't delete and only stored messages for the clients get deleted.
> I read your code and determined that line 142 in context.c deletes the subscriptions for a clean_session client and the next line deletes the messages associated with it. I tried commenting them out but the results failed for my use case.
> The question is, how I can delete the messages but keep the subscriptions when clients connect with clean_session?
> Thank you Roger...
>
> --
> You received this question notification because you are a member of
> Mosquitto PPA, which is an answer contact for mosquitto.

Revision history for this message
Bardya Momeni (vaskodogama) said :
#5

Thanks Roger Light, that solved my question.