如何在nodejs stompit中检查套接字连接是否可用

How to check socket connection is available or not in nodejs stompit

我在节点 js 中使用 stompit 模块连接 activeMQ。

我的问题:在stompit.ConnectFailover

中无法识别代理是否已连接

这是我的代码:

var stompit = require('stompit')

var connectionManager = new stompit.ConnectFailover();

connectionManager.addServer({
  'host': 'localhost',
  'port': 61623,
  'connectHeaders':{
    ...
  }
});

var channel = new stompit.Channel(connectionManager);

var subscribeHeaders = {
    'destination': '/queue/test',
    'ack': 'client'
};


channel.subscribe(subscribeHeaders, function(error, message){
    if (error) {
        console.log(error);
        return;
    }  
});

//send . But not throw error , even broker is not started
//always trying to reconnect
sendDlQ(subscribeHeaders, 'Hello');


function sendDlQ(header, body){
     channel.send(header, body);
}

每当调用发送方法,总是成功。 连broker都没有启动。

如何在发送前识别代理是否已连接?

stompit 库Channel.js中的连接选项已经可用

检查if(channel._client != null && !channel._closed)