2016-02-29 116 views
0

我正在使用stompit STOMP客戶端。 github - https://github.com/gdaws/node-stomp[stompit STOMP客戶端]故障轉移無法正常使用STOMP生產者

我正在使用ConnectFailover API進行重新連接管理。我有下面的代碼:

var stompit = require('stompit') var reconnectOptions = { 'maxReconnects': 100, 'randomize' : false }; var connManager = new stompit.ConnectFailover("failover:(stomp://mqbroker.nyc:61613,stomp://failovermqbroker.nyc:61613)", reconnectOptions); connManager.on('error', function(error) { var connectArgs = error.connectArgs; var address = connectArgs.host + ':' + connectArgs.port; console.error('Could not connect to ' + address + ' : ' + error.message); }); connManager.on('connecting', function(connector) { var address = connector.serverProperties.remoteAddress.transportPath; console.log('Connecting to ' + address); }); var totalMsgs = 50; var count = 0; var delayMs = 10000; connManager.connect(function(error, client, reconnect) { if (error) { console.log("terminal error, given up reconnecting: " + error); return; } client.on('error', function(error) { // destroy the current client client.destroy(error); // calling reconnect is optional and you may not want to reconnect if the // same error will be repeated. reconnect(); }); var sendParams = { 'destination' : '/queue/myqueue', 'persistent' : 'true' } function sendMsg(){ setTimeout(function() { console.log ('sending message ' + (count)); client.send(sendParams).end('Hello number ' + (count)); if (count++ < totalMsgs) { sendMsg(count); } else { client.send(sendParams).end('DISCONNECT'); client.disconnect(); console.log("Done."); } }, delayMs); } sendMsg(); });

的問題是,當客戶端從消息代理斷開,製片人一直在執行SENDMSG代碼,這將導致在2-3之間信息的損失。我希望客戶端在斷開狀態時停止執行,並在連接到故障轉移實例時恢復。

我是否錯誤地使用了API?什麼纔是實現這個目標的正確方法?

已經入侵了一段時間,但該API缺少關於如何使用這些功能的小文檔。感謝所有的幫助。

感謝, xabhi

回答

0

沒有問題的API,但與setTimeout的代碼。當客戶端發現連接失敗時,我應該清除超時。

相關問題