2014-01-09 46 views
4

我在PhoneGap上使用web-stomp插件+ SockJS/Stomp.js,並觀察到在情況下(可能與網絡有關),流量可以停止而不會觸發連接錯誤。爲了解決這個問題,我認爲我可以使用心臟跳動,所以我增加了以下我的JS:如何爲RabbitMQ啓用服務器端心跳?

function Connect() { 
    console.log('Connecting...'); 
    // Connect 
    var ws = new SockJS(mq_url); 
    client = Stomp.over(ws); 
    client.heartbeat.outgoing = 5000; // if 5000 means client will send heart beat every 5000ms 
    client.heartbeat.incoming = 5000; // if 0 means client does not want to receive heartbeats from server 
    client.debug = function (str) { 
     $("#debug").append(timeStamp() + str + "<br>"); 
     varmessage = str; 
    }; 
    client.connect(
    mq_username, mq_password, on_connect, on_connect_error, mq_vhost); 
} 

但是,服務器並不那麼下面的錯誤被拋出送心臟的跳動:

-> PING 
-> PING 
did not receive server activity for the last 10017ms 
Whoops! Lost connection to undefined 

我試圖添加heartbeat param到rabbitmq.config,但那似乎不起作用。文檔沒有提及心跳參數是用於客戶端還是服務器心跳。

[ 
     {rabbit, [ 
       {cluster_nodes, {['[email protected]'], disc}}, 
       {cluster_partition_handling, autoheal}, 
     {heartbeat, 1} 
     ]}, 

回答

2

心跳參數在客戶端上實現。 RabbitMQ將響應客戶端發出的心跳。服務器可以請求客戶端以一定的時間間隔發送心跳,但客戶端無需關注。 AMQP Reference; RabbitMQ reference