我的后端将消息推送到rabbitmq队列,我需要获取这些消息以显示在消息的前端部分,因为消息必须按特定顺序排列,我不能使用异步方法。
我写了这段代码
var open require("amqplib").connect("amqp://guest:guest@localhost:5682");
var queue = "developer";
export default {
name: 'Subsriber',
data: function() {
return {
selected: "",
services: [],
}
},
mounted() {
var url = "http://10.0.9.134:5060/services/scripts";
this.services = []; // empty the existing list first.
setTimeout(() => {
axios.get(url)
.then(response => {
this.services = response.data;
})
}, 2000)
open.then(function(conn){
return conn.createChannel();
}).then(function(ch){
return ch.assertQueue(queue).then(function(ok){
return ch.consume(queue, function(msg){
if (msg != null){
console.log(msg.content.toString());
}
});
});
});
}
但是我收到了这个错误:
"Unhandled rejection TypeError: QS.unescape is not a function
openFrames@webpack-internal:///./node_modules/_amqplib@0.5.2@amqplib/lib/connect.js:50:1
connect@webpack-internal:///./node_modules/_amqplib@0.5.2@amqplib/lib/connect.js:145:14
connect/<@webpack-internal:///./node_modules/_amqplib@0.5.2@amqplib/channel_api.js:7:12
connect@webpack-internal:///./node_modules/_amqplib@0.5.2@amqplib/channel_api.js:6:10
@webpack-internal:///./node_modules/babel-loader/lib/index.js!./node_modules/vue-loader/lib/selector.js?type=script&index=0!./src/components/SelectServices.vue:56:12
["./node_modules/babel-loader/lib/index.js!./node_modules/vue-loader/lib/selector.js?type=script&index=0!./src/components/SelectServices.vue"]@http://10.0.9.134/app.js:1251:1
__webpack_require__@http://10.0.9.134/app.js:679:1
hotCreateRequire/fn@http://10.0.9.134/app.js:89:20
@webpack-internal:///./src/components/SelectServices.vue:1:148
["./src/components/SelectServices.vue"]@http://10.0.9.134/app.js:1804:1
__webpack_require__@http://10.0.9.134/app.js:679:1
hotCreateRequire/fn@http://10.0.9.134/app.js:89:20
@webpack-internal:///./src/router/index.js:4:85
["./src/router/index.js"]@http://10.0.9.134/app.js:1820:1
__webpack_require__@http://10.0.9.134/app.js:679:1
hotCreateRequire/fn@http://10.0.9.134/app.js:89:20
@webpack-internal:///./src/main.js:4:66
["./src/main.js"]@http://10.0.9.134/app.js:1812:1
__webpack_require__@http://10.0.9.134/app.js:679:1
hotCreateRequire/fn@http://10.9.0.134/app.js:89:20
[0]@http://10.9.1.147/app.js:1829:18
__webpack_require__@http://10.0.9.134/app.js:679:1
@http://10.9.0.134/app.js:725:18
@http://10.9.0.134/app.js:1:1"