Mosquitto 不应存储和发送离线消息

Mosquitto should not store and send offline messages

我尽量不接收离线消息 我的情况是,如果客户端 1 处于离线状态并且客户端 2 正在发送消息,那么客户端 1 在重新连接时不应收到任何旧消息,并且他应该在重新连接后接收到发送的消息。我在客户端和 mosquitto 服务器上使用 mqtt 库(npm)。我已经尝试 {clean:true} 并使用 {qos:0} 发布和订阅,它不是 working.This 是我的代码

客户端 2:

 this.client = mqtt.connect(url, {
  clean: true
}
this.client.publish("mqtt/location", JSON.stringify(data1) ,{qos: 0});

客户端 1:

this.client = mqtt.connect(url, {
      clean: true
}
this.client.subscribe("mqtt/location", {qos: 0});
this.client.on("message", function(topic, payload) {
console.log(payload);
})

谢谢

如果您将 clean session 设置为 true,那么唯一的其他解释是您收到的消息是使用保留位集发布的。您无法阻止您的客户端接收这些消息,但您可以检测到它们。您从具有保留位设置的代理收到的任何已发布消息是 "old".