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

时间:2018-02-01 07:21:56

标签: mqtt mosquitto

如果client1处于脱机状态且client2正在发送消息,那么我尝试不获取我的场景下的离线消息,因此client1在重新连接时不应接收任何旧消息,并且他应该接收重新连接后发送的消息。我在客户端和mosquitto服务器上使用mqtt库(npm)。我已尝试{qos:0}并使用 this.client = mqtt.connect(url, { clean: true } this.client.publish("mqtt/location", JSON.stringify(data1) ,{qos: 0}); 发布和订阅,但无效。这是我的代码

客户端2:

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

客户端1:

raise TypeError('view must be a callable or a list/tuple in the case of include().') TypeError: view must be a callable or a list/tuple in the case of include().

由于

1 个答案:

答案 0 :(得分:1)

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

相关问题