forked from rabbitmq/rabbitmq-tutorials
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathworker.js
More file actions
20 lines (16 loc) · 705 Bytes
/
worker.js
File metadata and controls
20 lines (16 loc) · 705 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
var amqp = require('amqp');
var connection = amqp.createConnection({host: 'localhost'});
connection.on('ready', function(){
connection.queue('task_queue', {autoDelete: false,
durable: true}, function(queue){
console.log(' [*] Waiting for messages. To exit press CTRL+C');
queue.subscribe({ack: true, prefetchCount: 1}, function(msg){
var body = msg.data.toString('utf-8');
console.log(" [x] Received %s", body);
setTimeout(function(){
console.log(" [x] Done");
queue.shift(); // basic_ack equivalent
}, (body.split('.').length - 1) * 1000);
});
});
});