eclipse / paho.mqtt.javascript

paho.mqtt.javascript
Other
1.14k stars 468 forks source link

Socket closed when subscribe 3000 topics #152

Open flynn-shu opened 6 years ago

flynn-shu commented 6 years ago

AMQJS0008I Socket closed

    function onConnect() {
        // Once a connection has been made, make a subscription and send a message.
        console.log("onConnect");
        // client.subscribe("World");
        //about 3000 topics
        for (var i = 0; i < topics.length; i++) {
            var topic = topics[i];
            for (var key in topic) {
                client.subscribe(key);
                //console.log("subscribe:"+key); when add this line will be ok. It seems to be blocking  
 current thread
            }
        }

    }

    // called when the client loses its connection
    function onConnectionLost(responseObject) {
        if (responseObject.errorCode !== 0) {
            console.log("onConnectionLost:" + JSON.stringify(responseObject));
        }else{
            console.log("onConnectionLost:" + 0 );
        }
    }

How to subscribe to multiple topics using one request? If have any idea how to solve this issue, please help me!

jpwsutton commented 6 years ago

In the version of the client currently in the develop branch, you can now subscribe to multiple topics in an array: client.subscribe(["tennis", "football", "rugby"]);

This will be available in the release version sometime in late June.