Hello,
i've got a problem regarding persistent sessions when connecting from Node-RED to my Mosquitto broker.
Im currently running Node-RED v2.2.2 and Nodejs v14.19.1 on my Raspberry Pi. The server running the mqtt.js-script i'll mention later is running Nodejs v.16.15.1.
Regarding mqtt, i'm using the nodes that are contained in the basic Node-RED installation.
The mosquitto broker is configured to use mqtts and mqtt v5 and the basic stuff is working fine. I can send messages, i can receive messages and the will and birth messages are working as expected aswell.
Also i've set persistence true
and persistent_client_expiration 14d
in my mosquitto.conf
.
When i connect to the broker with my mqtt.js script, where the client is set to clean: false
and sessionExpiryInterval: 2592000
i can see in the mosquitto.db
that the client has the values Session expiry time: 0
and Session expiry interval: 2592000
. For this client everything works perfectly, when i reconnect i don't receive any old retained messages and missed messages are received. I can also see that the missed messages are sent in the mosquitto.log
file
However, when i connect with a client from Node-RED where the Use clean start
-Box isn't checked and the Session Expiry (secs)
is set to 2592000, this client has Session expiry time: 0
and Session expiry interval: 0
in the mosquitto.db
. In this case it seems like i don't receive any old retained messages, but i also don't receive any missed messages. This is also confirmed by the mosquitto.log
, where it doesn't mention any messages that are sent to the client when it connects.
The messages i want to receive are all sent with qos: 2
. For subscription in NodeRED i use a dynamic subscription
with the following function node in front:
msg.action = "subscribe";
msg.topic = {topic:flow.get("mqtt_topic") + "/some_topic", qos:2, nl:false, rap:true, rh:true};
return msg;
This subscription is triggered by an inject node that is injected once 0.1 seconds after flow startup.
The messages are neither received when i stop Node-RED, send the message, and then restart Node-RED nor when i unplug the network cable, wait for the last will to trigger, send the message and then plug it in again. When i don't wait for the last will when just unplugging the network cable the message gets through because the client hasn't officially disconnected from the broker yet.
Is there anything wrong with my subscription configuration or are there any other settings in the Node-RED mqtt-broker
node i have to set?
To me it looked like those two settings are the only ones related to persistent sessions in the broker node.
Or do you have any other idea why it might not work like i expect it to?