客户端如何使用设置为 false 的 clean-session 标志连接到 MQTT Broker

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

Clean Session 支持消息的持久化。默认值 Clean Session is true.

因为我们可以使用请求负载设置 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

谁能告诉我客户端如何将 clean-session 参数设置为 false? 我们可以用请求负载设置这个标志还是 还有其他方法吗??

清洁会话标志在 MQTT 客户端连接时设置。

这是在 CONNECT 数据包中作为 connect flags 的一部分完成的。

如果您使用的是 mosquitto_sub,则默认使用干净会话进行订阅。可以设置 -c--disable-clean-session 标志以启用持久会话。

使用此标志时需要设置 MQTT 客户端 ID,以便代理可以通过客户端 ID 跟踪订阅。来自 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