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

去掉amqblib

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