提问者:小点点

如何为RabbitMQ启用服务器端心跳?


我在PhoneGap上使用web-timp插件SockJS/Stomp. js,观察到在某些情况下(可能与网络有关),流量可以停止而不会触发连接错误。为了解决这个问题,我想我可以使用心跳,所以我在我的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);
}

但是,服务器不发送心跳,因此会引发以下错误:

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

我尝试了将心跳参数添加到Rabbitmq. config,但似乎不起作用。文档没有提到心跳参数是用于客户端还是服务器心跳。

[
       {rabbit, [
                {cluster_nodes, {['rabbit@server'], disc}},
                 {cluster_partition_handling, autoheal},
         {heartbeat, 1}
        ]},

共1个答案

匿名用户

心跳参数在客户端实现,RabbitMQ会响应客户端发出的心跳,服务器可以请求客户端以一定的间隔发送心跳,但客户端不必跟随。AMQP参考;RabbitMQ参考