【问题标题】:Client potentially overloading mqtt broker客户端可能超载 mqtt 代理
【发布时间】:2015-12-05 01:06:14
【问题描述】:

我正在使用 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 主题。用户运行调用代码的网页,然后关闭选项卡。没有明确关闭连接或关闭主题的代码。 MQTT 代理会死于 RAM 过载吗?

【问题讨论】:

    标签: javascript node.js mqtt


    【解决方案1】:

    When the tab is closed the websocket connection will also get closed so the broker should clean up the session, also if no messages or pings are received inside the keepalive period then the connection will also be cleaned up.

    主题不能关闭,没有所有权或打开/关闭的概念,它们只是消息路由的标识符。

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

    【讨论】:

    • 谢谢。赞成并被选为答案。我正在使用用 node.js 编写的 mosca MQTT 代理。你会认为这是一个写得很好的经纪人吗?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-04-08
    • 2011-07-11
    • 1970-01-01
    相关资源
    最近更新 更多