长连接修复

master V2.1.9
yujialong 7 months ago
parent 9953106b2f
commit cf67d8a099
  1. 25
      src/components/TestPanel.vue

@ -1187,16 +1187,16 @@ export default {
// websocket // websocket
// socket // socket
open () { open () {
console.log("socket连接成功"); // console.log("socket");
}, },
// socket // socket
error () { error () {
console.log("连接错误"); // console.log("");
}, },
// //
getMessage (msg) { getMessage (msg) {
console.log("==websocket接收数据=="); // console.log("==websocket==");
console.log(JSON.parse(msg.data)); // console.log(JSON.parse(msg.data));
const { content } = JSON.parse(msg.data) const { content } = JSON.parse(msg.data)
// 1234-id // 1234-id
if (content == 1 && this.projectPermissions === 2) { if (content == 1 && this.projectPermissions === 2) {
@ -1207,7 +1207,7 @@ export default {
}, },
// socket // socket
close () { close () {
console.log("socket已经关闭"); // console.log("socket");
}, },
// socket // socket
initSocket ({ id, account }) { initSocket ({ id, account }) {
@ -1227,6 +1227,8 @@ export default {
// let ws = new WebSocket(`ws://124.71.74.9:15674/ws`); // let ws = new WebSocket(`ws://124.71.74.9:15674/ws`);
let ws = new WebSocket(`wss://python.occupationlab.com/ws`); let ws = new WebSocket(`wss://python.occupationlab.com/ws`);
this.client = Stomp.over(ws); this.client = Stomp.over(ws);
this.client.heartbeat.outgoing = 0
this.client.heartbeat.incoming = 0
// //
const headers = { const headers = {
login: MQTT_USERNAME, login: MQTT_USERNAME,
@ -1235,17 +1237,18 @@ export default {
// //
this.client.connect(headers.login, headers.passcode, this.onConnected, this.onFailed, 'pyhost'); this.client.connect(headers.login, headers.passcode, this.onConnected, this.onFailed, 'pyhost');
}, },
onConnected: function () { onConnected () {
// //
this.clientTopic = '/amq/queue/pythonQueue_' + this.accountId; this.clientTopic = '/amq/queue/pythonQueue_' + this.accountId;
this.client.subscribe(this.clientTopic, this.responseCallback, this.onFailed); this.client.subscribe(this.clientTopic, this.responseCallback, this.onFailed);
}, },
onFailed: function (frame) { onFailed (frame) {
console.log("MQ Failed: " + frame); console.log("MQ Failed: " + frame);
// this.$message.error('') // this.client.reset().start();
this.connect()
}, },
// //
responseCallback: function (frame) { responseCallback (frame) {
const data = JSON.parse(frame.body) const data = JSON.parse(frame.body)
console.log("接收信息:", data, typeof data, newmain, newmain.$emit); console.log("接收信息:", data, typeof data, newmain, newmain.$emit);
@ -1262,7 +1265,7 @@ export default {
} }
}, },
// //
close: function () { close () {
this.client.disconnect(function () { this.client.disconnect(function () {
console.log("已退出账号"); console.log("已退出账号");
}) })
@ -1271,7 +1274,7 @@ export default {
// //
heartbeatDetection () { heartbeatDetection () {
setInterval(async () => { setInterval(async () => {
await this.$get(this.api.heartbeatDetectionRabbit) // await this.$get(this.api.heartbeatDetectionRabbit)
await this.$get(this.api.heartbeatDetection) await this.$get(this.api.heartbeatDetection)
}, 55 * 1000) }, 55 * 1000)
}, },

Loading…
Cancel
Save