Persistant Session & Queuing Message, Session Expiry

Hi Team,

I trying to acheive the persistant session & Queuing message in HiveMQ. But it not working properly.
I tried the below commands, but it doesn’t work.

For Publishing a Message used Shell command prompt:
mqtt> con -i myClientTest --no-cleanStart -se 1000
myClientTest@localhost> pub -t home -m Hello
myClientTest@localhost> pub -t home -m Hello -q 1 -r
myClientTest@localhost> pub -t home -m Hello1 -q 1 -r
myClientTest@localhost> pub -t home -m Hello12 -q 1 -r
myClientTest@localhost> pub -t home -m Hello123 -q 1 -r
myClientTest@localhost> pub -t home -m Hello -q 1 -r
myClientTest@localhost> pub -t home -m Hello1 -q 1 -r
myClientTest@localhost> pub -t home -m Hello2 -q 1 -r

For Subscribing a Topic:
./mqtt-cli sub -t home

Can you please provide me another solution to work with.

And Also I have an issue in Session Expiry.
Can you give me some tips to achieve this.

Thanks,
Hari

Hi @Harry ,

Great that you are interested in MQTT and HiveMQ, welcome to the community!

I am not 100% clear about “I trying to acheive the persistant session & Queuing message”. Perhaps you want to connect the subscriber first, then kill its session without sending a DISCONNECT packet to the broker, then publish a few messages to the topic, and then connect the subscriber again (i.e. using the same --identifier)?

Kind regards,
Dasha from HiveMQ Team

1 Like

Hi @Daria_H
Thank you for your response,
I also subscribed the same topic in another terminal but its not work as exact output that is mentioned in Document.
I tried same steps that is mentioned in the document. Still I didn’t get an expect.
Regards,
Harry.

Hi @Harry ,

It is unclear what do you mean by “its not work as expected”. Could you be more specific?

Thanks,
Dasha from HiveMQ team

1 Like

Hi @Daria_H


I tried to achieve Queuing message still its not working, can you please give some insights for me?

Hi @Harry ,

Please share the full config.xml

Tnx!

1 Like

Hi @Daria_H
Below attached the config file for reference

<?xml version="1.0"?>
<hivemq>

    <listeners>
        <tcp-listener>
            <port>1884</port>
            <bind-address>0.0.0.0</bind-address>
        </tcp-listener>
    </listeners>

    <!-- <cluster>
        <enabled>true</enabled>
        <control-center>
         <listeners>
         <http>
         <port>8881</port>
         <bind-address>127.0.0.1</bind-address>
         </http>
         </listeners>
         </control-center> -->

          <cluster>
     <enabled>true</enabled>
     <transport>
         <udp>
             <!-- replace this IP with the IP address of your interface -->
             <bind-address>127.0.0.1</bind-address>
             <bind-port>8881</bind-port>
             <multicast-enabled>true</multicast-enabled>
             <!-- replace this IP with the multicast IP address of your interface -->
             <multicast-address>228.8.8.8</multicast-address>
             <multicast-port>45588</multicast-port>
         </udp>
     </transport>
     <discovery>
         <multicast/>
     </discovery>

     <failure-detection>
            <heartbeat>
                <enabled>true</enabled>
                <interval>5000</interval>
                <timeout>15000</timeout>
            </heartbeat>
        </failure-detection>
<!-- 
     <failure-detection>
            <heartbeat>
                <enabled>true</enabled>
                <interval>8000</interval>
                <timeout>40000</timeout>
            </heartbeat>
        </failure-detection> -->

 </cluster>

        <!-- <transport>
           <tcp> -->
                <!-- replace this IP with the IP address of your interface -->
                <!-- <bind-address>127.0.0.1</bind-address>
                <bind-port>1833</bind-port>
           </tcp>
        </transport>
        <discovery>
            <static>
                <node> -->
                    <!-- replace this IP with the IP address of your interface -->
                    <!-- <host>127.0.0.1</host>
                    <port>7800</port>
                </node>
                <node> -->
                    <!-- replace this IP with the IP address of another node -->
                    <!-- <host>127.0.0.1</host>
                    <port>7800</port>
                </node>
            </static>
        </discovery> -->

    <!-- </cluster> -->

    <!-- <cluster>

        <enabled>true</enabled>

        <transport>
            <tcp> -->
                <!-- replace this IP with the IP address of your interface -->
                <!-- <bind-address>127.0.0.1</bind-address>
                <bind-port>1833</bind-port>
            </tcp>
        </transport> -->

        <!-- <discovery>
            <static>
                <node> -->
                    <!-- replace this IP with the IP address of your interface -->
                    <!-- <host>192.168.1.1</host>
                    <port>7800</port>
                </node>
                <node> -->
                    <!-- replace this IP with the IP address of another node -->
                    <!-- <host>192.168.1.2</host>
                    <port>7800</port>
                </node>
                <node> -->
                    <!-- replace this IP with the IP address of another node -->
                    <!-- <host>192.168.1.3</host>
                    <port>7801</port>
                </node>
            </static>
        </discovery> -->

    <!-- </cluster> -->
    

    <mqtt-addons>
        <dropped-messages-topic>
            <enabled>true</enabled>
        </dropped-messages-topic>

        <!-- <expired-messages-topic>
            <enabled>true</enabled>
        </expired-messages-topic> -->

         <!-- <dead-messages-topic>
            <enabled>true</enabled>
        </dead-messages-topic> -->

    </mqtt-addons>
    
 
    <!-- <anonymous-usage-statistics>
        <enabled>true</enabled>
    </anonymous-usage-statistics> -->

        <mqtt>

        <queued-messages>
            <max-queue-size>100</max-queue-size>
            <strategy>discard</strategy>
        </queued-messages>

        <topic-alias>
            <enabled>true</enabled>
            <max-per-client>5</max-per-client>
        </topic-alias>

        <message-expiry>
            <max-interval>10</max-interval>  <!-- this value means no message expiry -->
        </message-expiry>

        <session-expiry>
            <max-interval>4294967295</max-interval> <!-- ~ 130 years -->
        </session-expiry>

        <keep-alive>
            <allow-unlimited>true</allow-unlimited>
            <max-keep-alive>65535</max-keep-alive>
        </keep-alive>

        <packets>
            <max-packet-size>100</max-packet-size> <!-- 256 MB -->
        </packets>

        <receive-maximum>
            <server-receive-maximum>10</server-receive-maximum>
        </receive-maximum>

        <quality-of-service>
            <max-qos>2</max-qos>
        </quality-of-service>

        <wildcard-subscriptions>
            <enabled>true</enabled>
        </wildcard-subscriptions>

        <shared-subscriptions>
            <enabled>true</enabled>
        </shared-subscriptions>

        <subscription-identifier>
            <enabled>false</enabled>
        </subscription-identifier>

        <retained-messages>
            <enabled>true</enabled>
        </retained-messages>

    </mqtt>

</hivemq>

The Client Session Queued Messages Persistence is responsible for storing the queued messages for offline clients
HiveMQ will save all missed messages for these topics if the client goes offline.

But I didn’t get an output, can you give me some insights for this.

Regards,

@Harry ,

Now create a persistent session for a subscriber:

mqtt sub -t Test -se 3600 --no-cleanStart -v -i Subscriber

Go to the localhost:8080 to the HiveMQ Control Center → Clients, Refresh the list, and note that your Subscriber client is connected with “clean start: false”.

Then from another terminal window, do find the subscribers process and terminate it.

To find the process PID:

ps -ef | head -1; ps -ef | grep mqtt | grep -v grep

To terminate the PID:

kill -s TERM <PID>

Go to the HiveMQ Control Center → Clients again, Refresh the list, and see that your Subscriber is still in the list but in the disconnected state.

Now publish a few messages to the Test topic. Note that only messages QoS 1 and 2 will be persisted:

for i in {0..1000}; do mqtt publish --topic Test --message "Hello$i" --identifier Publisher --qos 1 --verbose; sleep 1; done

Go to the HiveMQ Control Center → Clients again, refresh the list, and see if the current queue size is changing for the Subscriber:

Go to the HiveMQ Control Center → Dashboard and check the queue size:
image

When you are tired of publishing, go to the Publisher’s terminal window and terminate it with Ctrl+C. You might need to Ctrl+C more than once.

I hope this helps
Kind regards,
Dasha from HiveMQ team

1 Like

Hi @Daria_H

Thank you for your response, I followed the steps that you mentioned in previous message now its working fine.


Regards and Thanks
Harry.