我在PhoneGap上使用web-stomp插件+ 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);
}
Run Code Online (Sandbox Code Playgroud)
但是,服务器不发送心跳,因此抛出以下错误:
-> PING
-> PING
did not receive server activity for the last 10017ms
Whoops! Lost connection to undefined
Run Code Online (Sandbox Code Playgroud)
我尝试将心跳param添加到rabbitmq.config,但这似乎不起作用.doc没有提到heartbeat参数是用于客户端还是服务器心跳.
[
{rabbit, [
{cluster_nodes, {['rabbit@server'], disc}},
{cluster_partition_handling, autoheal},
{heartbeat, 1}
]},
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4739 次 |
| 最近记录: |