-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Expand file tree
/
Copy pathworker.js
More file actions
executable file
·32 lines (26 loc) · 885 Bytes
/
worker.js
File metadata and controls
executable file
·32 lines (26 loc) · 885 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#!/usr/bin/env node
const amqp = require('amqplib');
async function main() {
const connection = await amqp.connect('amqp://localhost');
const channel = await connection.createChannel();
const queue = 'task_queue';
await channel.assertQueue(queue, {
durable: true,
arguments: { 'x-queue-type': 'quorum' }
});
channel.prefetch(1);
console.log(" [*] Waiting for messages in %s. To exit press CTRL+C", queue);
channel.consume(queue, function(msg) {
const secs = msg.content.toString().split('.').length - 1;
console.log(" [x] Received %s", msg.content.toString());
setTimeout(function() {
console.log(" [x] Done");
channel.ack(msg);
}, secs * 1000);
}, {
// manual acknowledgment mode,
// see /docs/confirms for details
noAck: false
});
}
main();