简体   繁体   中英

How client connects to the MQTT Broker with the clean-session flags set as false

Clean Session supports persistence of messages. By default the value of Clean Session is true .

As we can set the Qos and retain flag value with the request payload as below:

docker run -it --rm --name mqtt-publisher --network \\ fiware_default efrecon/mqtt-client pub -h mosquitto -m "c|1234" \\ -t "/4jggokgpepnvsb2uv4s40d59ov/motion001/attrs" -q 2 -r -d

can any one tell me how a client can set clean-session parameter as false? can we set this flag with request payload or there is other method for this ??

The clean session flag is set when the MQTT client connects.

This is done in the CONNECT packet as part of the connect flags .

If you are using mosquitto_sub then it defaults to using a clean session for subscriptions. The -c or --disable-clean-session flag can be set to enable a persistent session.

The MQTT client id needs to be set when using this flag so the broker can track the subscriptions by client id. From https://mosquitto.org/man/mosquitto_sub-1.html :

-c, --disable-clean-session

Disable the 'clean session' flag. This means that all of the subscriptions for the client will be maintained after it disconnects, along with subsequent QoS 1 and QoS 2 messages that arrive. When the client reconnects, it will receive all of the queued messages.

If using this option, the client id must be set manually with --id

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM