Commit 73b3ac68 authored by 郝聪敏's avatar 郝聪敏

去掉amqblib

parent 66b1b5eb
......@@ -582,36 +582,36 @@ class HomeService extends Service {
}
async publisher() {
const ch = await this.app.amqplib.createChannel();
await ch.assertQueue(queueName, { durable: false });
for (let i = 0; i < 5; i++) {
await ch.sendToQueue(queueName, Buffer.from(`第${i}条消息`));
}
await ch.close();
// const ch = await this.app.amqplib.createChannel();
// await ch.assertQueue(queueName, { durable: false });
// for (let i = 0; i < 5; i++) {
// await ch.sendToQueue(queueName, Buffer.from(`第${i}条消息`));
// }
// await ch.close();
}
async consumer() {
let ch;
try {
ch = await this.app.amqplib.createChannel();
await ch.assertQueue(queueName, { durable: false });
await ch.prefetch(1, false);
let i = 0;
await ch.consume(queueName, msg => {
try {
i++;
console.log('consumer', msg.content.toString());
if (i === 1) { throw new Error('出现异常'); }
ch.ack(msg);
} catch (err) {
this.ctx.logger.error(err);
ch.close();
}
}, { noAck: false });
} catch (err) {
this.ctx.logger.error(err);
if (ch) ch.close();
}
// let ch;
// try {
// ch = await this.app.amqplib.createChannel();
// await ch.assertQueue(queueName, { durable: false });
// await ch.prefetch(1, false);
// let i = 0;
// await ch.consume(queueName, msg => {
// try {
// i++;
// console.log('consumer', msg.content.toString());
// if (i === 1) { throw new Error('出现异常'); }
// ch.ack(msg);
// } catch (err) {
// this.ctx.logger.error(err);
// ch.close();
// }
// }, { noAck: false });
// } catch (err) {
// this.ctx.logger.error(err);
// if (ch) ch.close();
// }
}
}
......
......@@ -26,11 +26,11 @@ module.exports = appInfo => {
};
},
},
amqplib: {
client: {
url: 'amqp://qa:qatest@172.17.5.8:31342/egg-puppeteer',
},
},
// amqplib: {
// client: {
// url: 'amqp://qa:qatest@172.17.5.8:31342/egg-puppeteer',
// },
// },
};
// use for cookie sign key, should change to your own and keep security
......
......@@ -2,10 +2,10 @@
/** @type Egg.EggPlugin */
module.exports = {
amqplib: {
enable: true,
package: 'egg-amqplib',
},
// amqplib: {
// enable: true,
// package: 'egg-amqplib',
// },
redis: {
enable: true,
package: 'egg-redis',
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment