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}
]},
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With