Persistent Session / Queue Message Issue using HiveMQ MQTT CLI Client

Hi There,

I have HiveMQ Enterprise Edition installed in my machine.
I wanted to evaluate the persistence session or clean session feature.

I am using HiveMQ MQTT CLI client to connect and Publisher client and Subscriber client.

In Subscriber Client shell, I ran the following commands:

con -i subclient1 --no-cleanStart -V 5
sub -t test -q 2 -J -s

In Publisher Client shell, I ran the following commands:
con -i pubclient1 --no-cleanStart -V 5
pub -t test -q 2 -r -m ‘test0’
pub -t test -q 2 -r -m ‘test1’

Then in the Subscriber Shell, I was able to see the two messages.
Then disconnected the Subscriber Shell using ctrl C and then dis.

Then in Publisher Client shell, I ran the following commands:
pub -t test -q 2 -r -m ‘test2’
pub -t test -q 2 -r -m ‘test3’

In Subscriber Client shell, I ran the following commands:

con -i subclient1 --no-cleanStart -V 5
sub -t test -q 2 -J -s

I am not seeing the both the new messages “test2” and “test3”. Only seeing the last retained message “test3”. “test2” is lost.

Basically only the last one message is getting displayed at subscriber when it is connected back. All other messages are lost or not getting displayed.

Not sure what I am doing wrong. Can you please let me know.

Is something issue with the HiveMQ MQTT CLI client?

I went through your video in this link: Persistent Session and Queuing Messages - MQTT Essentials: Part 7

Thanks & Regards,
-Venkat

Hi @vgkkonda,

you forgot to add the session expiry to the connect command. The command below says connect and use existing session but the session expiry is 0 (meaning when client disconnects session is also gone):

con -i subclient1 --no-cleanStart -V 5

Fix → add -se (session expiry in seconds) to the connect command:

con -i subclient1 --no-cleanStart -V 5 -se 1000

This means when your client disconnects the broker stores the session for 1.000 seconds and then deletes it (if the client doesn’t reconnect in the meantime).

Greetings,
Michael

1 Like

Hi @michael_w,

I tried the above solution that you’ve provided. But it’s not working as expected, I couldn’t get the persistent messages back when I reconnect again even though I’ve configured 30000ms.

Can you guide me through the solution for it?

Hi @akash_99,

can you please post all the commands you used and mention at which point you disconnected the subscribing client, so I can take a look.

Greetings,
Michael from the HiveMQ team

Sure @michael_w,

I am using HiveMQ MQTT CLI Client. Starting from there, I’ve connected to shell through mqtt shell.

mqtt shell

In the subscriber client shell, I’ve configured the following:
con -i subclient --no-cleanStart -se 30000
sub -t mytopic -q2 -s

In the publisher client shell, I’ve configured the following;
con -i pubclient --no-cleanStart -se 30000
pub -t test -q2 -r -m ‘test0’
pub -t test -q2 -r -m ‘test1’

Then I disconnected using ctrl+C. Then I ran the following commands
pub -t test -q2 -r -m ‘test2’
pub -t test -q2 -r -m ‘test3’

In publisher, I connected mqtt shell and connected to same client and subscribed to the same topic using
con -i subclient --no-cleanStart -se 30000
sub -t mytopic -q2 -s

When I reconnect, I couldn’t get the ‘test3’ and ‘test4’

Can you please guide me and pinpoint the place I went ran. So that I can clear the issue

Regards,
Jerome Akash

Hi @akash_99,

so the easy solution would be to not use the mqtt shell, your use case can easily be reproduced with the mqtt sub and mqtt pub functions.

Connect and subscribe client:

mqtt sub -i subclient -t test -q 2 --no-cleanStart -se 30000

(optional) you can publish messages to be sure that client get messages:

mqtt pub -t test -q 2 -m message1
mqtt pub -t test -q 2 -m message2

Disconnect the subsciber client (ctrl + c), then publish messages again:

mqtt pub -t test -q 2 -m message3
mqtt pub -t test -q 2 -m message4

Reconnect subscriber:

mqtt sub -i subclient -t test -q 2 --no-cleanStart -se 30000

Here my try:

Hope this is enough, if you need the mqtt shell version let me know.

Greetings,
Michael

Hi @michael_w,

I tried the above provided commands, but it doesn’t work. Can you please provide me another solution to work with.

Regards,
Akash

Hi @akash_99 ,

Could you please elaborate a bit more on this? Please make sure that the following information is present in your description:

  • What command do you run
  • What is the actual outcome
  • What was expected outcome

If you like, you can record a short video of what you are doing.

Tnx,
Dasha

Hi @akash_99,

I think you are affected by: Fix cleanStart always being true by gitseti · Pull Request #317 · hivemq/mqtt-cli · GitHub
There was an regression so that --no-cleanStart is currently not respected.

My mqtt-cli version is 4.6.1 so I don’t have the regression. That’s why the commands worked for me but not for you.

You’ll have to wait until this PR is done.

Greetings,
Michael from the HiveMQ team