简体   繁体   English

mqtt连接上的更改将

[英]Change will on a mqtt connection

We are using the mqtt.js ( https://www.npmjs.com/package/mqtt ) client to connect to AWS IoT service. 我们正在使用mqtt.js( https://www.npmjs.com/package/mqtt )客户端连接到AWS IoT服务。

We can connect no problem and pass in last will with the following code 我们可以毫无问题地连接,并使用以下代码传递最后的意愿

var clientOptions = {
    will: {
        topic: "logout",
        payload: JSON.stringify({ _id: User.me._id, viewing: User.me.viewing })
    }
};  

client = mqtt.connect(signedUrl, clientOptions);

Now I want to update the will portion of the options--change the payload to have a new viewing property. 现在,我想更新选项的will部分-更改有效负载以具有新的查看属性。

Is there a way to update the will without disconnecting and triggering the old will? 有没有一种方法可以在不断开和触发旧遗嘱的情况下更新遗嘱?

There is no way to change the Last Will and Testament, it can only be set in the connect packet. 无法更改“最后遗嘱”,只能在连接数据包中进行设置。

But the Last Will and Testament should only fire if the client times out, not on a clean disconnect. 但是,只有在客户超时的情况下,才应解雇《最后遗嘱》,而不是在完全断开的情况下解雇。 This means you should be able to tell the client to disconnect and reconnect with a new LWT without triggering the old one to be published. 这意味着您应该能够告诉客户端断开连接并与新的LWT重新连接,而无需触发旧的LWT。

It you use clean session false and subscribe at QOS1 or better then you should not miss any messages when you reconnect as the broker should queue and deliver them on reconnect. 如果您使用干净的会话false并在QOS1或更高级别上进行订阅,则重新连接时不应丢失任何消息,因为代理应排队并在重新连接时传递它们。

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

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