源码:
const amqp =require('amqplib');
async function consumer() {
// 1. 创建链接对象
const connection = await amqp.connect('amqp://admin:admin@192.168.1.112:15672/');
// 2. 获取通道
const channel = await connection.createChannel();
// 声明参数
const exchangeName = 'fanout_koala_exchange';
const queueName = 'hello';
const routingKey = '';
// 声明一个交换机
await channel.assertExchange(exchangeName, 'fanout', { durable: true });
// 声明一个队列
await channel.assertQueue(queueName);
// 绑定关系(队列、交换机、路由键)
await channel.bindQueue(queueName, exchangeName, routingKey);
// 消费
await channel.consume(queueName, msg => {
console.log('Consumer:', msg.content.toString());
channel.ack(msg);
});
console.log('消费端启动成功!');
}
consumer();
报错:
PS E:\网页GIS-2021\fire-control\src\dbmanager> node MQconstructor.js
(node:16660) UnhandledPromiseRejectionWarning: Error: Socket closed abruptly during opening handshake
at Socket.endWhileOpening (E:\网页GIS-2021\fire-control\node_modules\amqplib\lib\connection.js:260:17)
at Socket.emit (events.js:388:22)
at endReadableNT (internal/streams/readable.js:1336:12)
at processTicksAndRejections (internal/process/task_queues.js:82:21)
请教一下各位高手,什么原因呢?