Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to enable server side heartbeat for RabbitMQ?

Tags:

rabbitmq

stomp

I'm using web-stomp plugin + SockJS/Stomp.js on PhoneGap and observed that under circumstances (probably related to network), traffic can stop without triggering a connection error. To solve this problem, I thought that I may use heart beat so I added the following to my js:

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);
}

However, the server doesn't send heart beat so the following error is thrown:

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

I tried adding heartbeat param to rabbitmq.config, but that didn't appear to work. The doc doesn't mention whether the heartbeat parameter is for client or server heartbeat.

[
       {rabbit, [
                {cluster_nodes, {['rabbit@server'], disc}},
                 {cluster_partition_handling, autoheal},
         {heartbeat, 1}
        ]},
like image 534
Joshua Avatar asked Nov 02 '22 07:11

Joshua


1 Answers

The heartbeat parameter is implemented on the client. RabbitMQ will respond to the heartbeat sent out by the client. The server can request clients to send heartbeats at a certain interval, but the client does not have to follow. AMQP Reference; RabbitMQ reference

like image 109
theMayer Avatar answered Nov 09 '22 09:11

theMayer