2022-11-06 12:00:55 +00:00
|
|
|
module.exports = class Queue {
|
2024-04-08 13:17:06 +00:00
|
|
|
constructor(consumer, name, conf) {
|
|
|
|
Object.assign(this, {consumer, name, conf});
|
2024-04-04 09:33:29 +00:00
|
|
|
}
|
2022-11-06 12:00:55 +00:00
|
|
|
|
2024-04-08 13:17:06 +00:00
|
|
|
async consume() {
|
|
|
|
const channel = await this.consumer.amqpConn.createChannel();
|
|
|
|
channel.prefetch(this.conf.amqpPrefetch);
|
|
|
|
await channel.assertQueue(this.name, {
|
|
|
|
durable: true
|
|
|
|
});
|
|
|
|
this.channel = channel;
|
|
|
|
|
|
|
|
await channel.consume(this.name,
|
|
|
|
msg => this.onConsume(msg));
|
2022-11-06 12:00:55 +00:00
|
|
|
}
|
|
|
|
}
|