├── .gitignore ├── package.json ├── app.js └── worker.js /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules/ -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "rabbitmq-workers", 3 | "version": "1.0.0", 4 | "description": "", 5 | "main": "index.js", 6 | "scripts": { 7 | "test": "echo \"Error: no test specified\" && exit 1" 8 | }, 9 | "keywords": [], 10 | "author": "", 11 | "license": "ISC", 12 | "dependencies": { 13 | "amqplib": "^0.5.2" 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /app.js: -------------------------------------------------------------------------------- 1 | var amqp = require('amqplib/callback_api'); 2 | 3 | amqp.connect('amqp://localhost:5672', function (err, conn) { 4 | conn.createChannel(function (err, ch) { 5 | var q = 'hello'; 6 | var msg = 'Hello World 123!'; 7 | ch.assertQueue(q, { durable: false }); 8 | ch.sendToQueue(q, new Buffer(msg)); 9 | console.log(" [x] Sent %s", msg); 10 | }); 11 | setTimeout(function () { conn.close(); process.exit(0) }, 500); 12 | }); -------------------------------------------------------------------------------- /worker.js: -------------------------------------------------------------------------------- 1 | var amqp = require('amqplib/callback_api'); 2 | 3 | amqp.connect('amqp://localhost:5672', function (err, conn) { 4 | conn.createChannel(function (err, ch) { 5 | var q = 'hello'; 6 | 7 | ch.assertQueue(q, { durable: false }); 8 | ch.prefetch(1); 9 | console.log(" [*] Waiting for messages in %s. To exit press CTRL+C", q); 10 | ch.consume(q, function (msg) { 11 | console.log(" [x] Received %s", msg.content.toString()); 12 | }, { noAck: true }); 13 | }); 14 | }); --------------------------------------------------------------------------------