异常:
Whoops! Lost connection to ws://xxxx:61614/stomp异常
最近使用stomp连接mq,发现此问题,记录一下。
客户端源码
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
<script type="text/javascript" src="stomp.js"></script>
</head>
<body>
<script type="text/javascript">
var url = "ws://127.0.0.1:61614/stomp";
var destination = "/topic/topicName";
var settings = {
websocket: {
heartbeatOutgoing: 1000 * 10,
heartbeatIncoming: 1000 * 10,
reconnectInterval: 1000 * 60 * 1
}
};
client = Stomp.client(url);
client.heartbeat.outgoing = 0;
client.heartbeat.incoming = 10000;
var error_callback = function(error) {
console.log(error);
console.log(error.body);
};
var headers = {
login: 'admin',
passcode: 'admin',
};
var callback = function(message) {
console.log(message.body);
alert(message.body);
};
var connect_callback = function(frame) {
client.subscribe(destination, callback,{'activemq.retroactive':true});
};
setTimeout(function(){connect_callback}, settings.websocket.reconnectInterval);
client.connect(headers, connect_callback, error_callback);
</script>
</body>
</html>
解决方案
原始代码
client.heartbeat.outgoing = settings.websocket.heartbeatOutgoing;
client.heartbeat.incoming = settings.websocket.heartbeatIncoming;
替换后代码
client.heartbeat.outgoing = 0;
client.heartbeat.incoming = 10000;
完美解决。
|