# Persistant Session & Queuing Message, Session Expiry

**URL:** <https://community.hivemq.com/t/persistant-session-queuing-message-session-expiry/1578>\
**Category:** Uncategorized\
**Created:** [November 9, 2022, 9:15am UTC](https://community.hivemq.com/t/persistant-session-queuing-message-session-expiry/1578 "2022-11-09T09:15:51Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Harry](https://avatars.discourse-cdn.com/v4/letter/h/f6c823/32.png) [@Harry](https://community.hivemq.com/u/Harry)\
**Post date:** [November 9, 2022, 9:15am UTC](https://community.hivemq.com/t/persistant-session-queuing-message-session-expiry/1578/1 "2022-11-09T09:15:51Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Daria\_H](https://avatars.discourse-cdn.com/v4/letter/d/dfb087/32.png) [@Daria\_H](https://community.hivemq.com/u/Daria_H)\
**Post date:** [November 10, 2022, 3:17pm UTC](https://community.hivemq.com/t/persistant-session-queuing-message-session-expiry/1578/2 "2022-11-10T15:17:13Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Harry](https://avatars.discourse-cdn.com/v4/letter/h/f6c823/32.png) [@Harry](https://community.hivemq.com/u/Harry)\
**Post date:** [December 13, 2022, 1:16pm UTC](https://community.hivemq.com/t/persistant-session-queuing-message-session-expiry/1578/4 "2022-12-13T13:16:11Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Daria\_H](https://avatars.discourse-cdn.com/v4/letter/d/dfb087/32.png) [@Daria\_H](https://community.hivemq.com/u/Daria_H)\
**Post date:** [December 13, 2022, 4:09pm UTC](https://community.hivemq.com/t/persistant-session-queuing-message-session-expiry/1578/5 "2022-12-13T16:09:57Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Harry](https://avatars.discourse-cdn.com/v4/letter/h/f6c823/32.png) [@Harry](https://community.hivemq.com/u/Harry)\
**Post date:** [December 14, 2022, 9:58am UTC](https://community.hivemq.com/t/persistant-session-queuing-message-session-expiry/1578/6 "2022-12-14T09:58:41Z")

</div>

Hi @Daria_H

 ![image](https://canada1.discourse-cdn.com/flex035/uploads/hivemq1/original/1X/56b0d9a343cdffe2bf010f74ae736fff0d18eb69.png)  
I tried to achieve Queuing message still its not working, can you please give some insights for me?

---

<div class="post-metadata">

**Author:** ![Daria\_H](https://avatars.discourse-cdn.com/v4/letter/d/dfb087/32.png) [@Daria\_H](https://community.hivemq.com/u/Daria_H)\
**Post date:** [December 14, 2022, 10:52am UTC](https://community.hivemq.com/t/persistant-session-queuing-message-session-expiry/1578/7 "2022-12-14T10:52:36Z")

</div>

Hi @Harry ,

Please share the full config.xml

Tnx!

---

<div class="post-metadata">

**Author:** ![Harry](https://avatars.discourse-cdn.com/v4/letter/h/f6c823/32.png) [@Harry](https://community.hivemq.com/u/Harry)\
**Post date:** [December 14, 2022, 12:17pm UTC](https://community.hivemq.com/t/persistant-session-queuing-message-session-expiry/1578/8 "2022-12-14T12:17:46Z")

</div>

Hi @Daria_H  
Below attached the config file for reference

```auto
<?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,

---

<div class="post-metadata">

**Author:** ![Daria\_H](https://avatars.discourse-cdn.com/v4/letter/d/dfb087/32.png) [@Daria\_H](https://community.hivemq.com/u/Daria_H)\
**Post date:** [December 14, 2022, 2:03pm UTC](https://community.hivemq.com/t/persistant-session-queuing-message-session-expiry/1578/9 "2022-12-14T14:03:20Z")

</div>

@Harry ,

Now create a persistent session for a subscriber:

```auto
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:

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

```

To terminate the PID:

```auto
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:

```auto
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:

 ![image](https://canada1.discourse-cdn.com/flex035/uploads/hivemq1/original/1X/ce00e7717cdc34469075233c634fd2905b611322.png)

Go to the HiveMQ Control Center → Dashboard and check the queue size:  
 ![image](https://canada1.discourse-cdn.com/flex035/uploads/hivemq1/original/1X/5e4be92b52f794e347a97e278570ea2cde1cedd7.png)

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

---

<div class="post-metadata">

**Author:** ![Harry](https://avatars.discourse-cdn.com/v4/letter/h/f6c823/32.png) [@Harry](https://community.hivemq.com/u/Harry)\
**Post date:** [December 14, 2022, 3:08pm UTC](https://community.hivemq.com/t/persistant-session-queuing-message-session-expiry/1578/10 "2022-12-14T15:08:39Z")

</div>

Hi @Daria_H

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

 ![image](https://canada1.discourse-cdn.com/flex035/uploads/hivemq1/original/1X/c80f8049315f870ae38027ae34ddc011bf0a3926.png)  
 ![image](https://canada1.discourse-cdn.com/flex035/uploads/hivemq1/original/1X/d50f7ff26b6727e0a3fd3fe94dbf649f73b90635.png)

Regards and Thanks  
Harry.
