简体   繁体   English

客户端如何将Clean-Session标志设置为false来连接到MQTT Broker

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

Clean Session supports persistence of messages. Clean Session支持消息的持久性。 By default the value of Clean Session is true . 默认情况下, Clean Session is true

As we can set the Qos and retain flag value with the request payload as below: 因为我们可以设置Qos并使用请求有效负载保留标志值,如下所示:

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 docker运行-it --rm --name mqtt-publisher --network \\ fiware_default efrecon / mqtt-client pub -h mosquitto -m“ c | 1234” \\ -t“ / 4jggokgpepnpnsb2uv4s40d59ov / motion001 / attrs” -q 2 -r -d

can any one tell me how a client can set clean-session parameter as false? 谁能告诉我客户端如何将clean-session参数设置为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. 当MQTT客户端连接时,将设置清洁会话标志。

This is done in the CONNECT packet as part of the connect flags . 这是在CONNECT数据包中作为连接标志的一部分完成的。

If you are using mosquitto_sub then it defaults to using a clean session for subscriptions. 如果使用的是mosquitto_sub则默认为使用干净会话进行订阅。 The -c or --disable-clean-session flag can be set to enable a persistent session. 可以将-c--disable-clean-session标志设置为启用持久会话。

The MQTT client id needs to be set when using this flag so the broker can track the subscriptions by client id. 使用此标志时需要设置MQTT客户机ID,以便代理可以按客户机ID跟踪预订。 From https://mosquitto.org/man/mosquitto_sub-1.html : https://mosquitto.org/man/mosquitto_sub-1.html

-c, --disable-clean-session -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. 这意味着客户端断开连接后,将维护所有的客户端订阅,以及随后到达的QoS 1和QoS 2消息。 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 如果使用此选项,则必须使用--id手动设置客户端ID

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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