客户端可能会超载 mqtt 代理

Client potentially overloading mqtt broker

我正在使用 MQTT node.js mosca 代理。我运行它用这个命令;

mosca -v --http-port 3000 --http-bundle --http-static ./ | bunyan

我有一个浏览器 mqtt 客户端。代码如下所示;

var mqtt_client = mqtt.connect('ws://127.0.0.1:3000');
            mqtt_client.subscribe('hello/world');
            mqtt_client.on('connect', function () {
                console.log("MQTT connected");
            });

        mqtt_client.on("message", function(topic, payload) {
            console.log([topic, payload].join(": "));
            //mqtt client connection not closed as line below is commented  
            //mqtt_client.end();
        });

假设我有许多类似的浏览器客户端,每个都订阅了不同的 mqtt 主题。用户运行s调用代码的网页,然后关闭标签页。没有明确关闭连接或关闭主题的代码。 MQTT 代理会因 RAM 过载而死吗?

关闭选项卡时,Websocket连接也将关闭,以便经纪人应清理会话,同样,如果在存储期内未收到任何消息或ping,则还将清理连接。

主题无法关闭,没有所有权或open/closed的概念,它们只是消息路由的标识符。

如果您使用大于 0 的 QOS 和持久会话,则在等待特定客户端重新连接时消息可能会累积,但是编写良好的代理应该将这些存储在磁盘上而不是内存中。