├── .gitattributes ├── LICENSE ├── README.md ├── index.js ├── package-lock.json └── package.json /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2019 Swathi Prasad 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # node-queue 2 | A simple queue implementation in Node.js 3 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | const amqp = require('amqplib/callback_api'); 2 | 3 | amqp.connect('amqp://localhost', function(error, connection) { 4 | if (error) { 5 | throw error; 6 | } 7 | connection.createChannel(function(error1, channel) { 8 | if (error1) { 9 | throw error1; 10 | } 11 | 12 | let queue = 'node_queue'; 13 | let msg = 'Test message'; 14 | 15 | channel.assertQueue(queue, { 16 | durable: true 17 | }); 18 | channel.sendToQueue(queue, Buffer.from(msg), { 19 | persistent: true 20 | }); 21 | console.log("Sent '%s'", msg); 22 | }); 23 | setTimeout(function() { 24 | connection.close(); 25 | process.exit(0) 26 | }, 500); 27 | }); 28 | 29 | 30 | amqp.connect('amqp://localhost', function(error0, connection) { 31 | if (error0) { 32 | throw error0; 33 | } 34 | connection.createChannel(function(error1, channel) { 35 | if (error1) { 36 | throw error1; 37 | } 38 | var queue = 'node_queue'; 39 | 40 | channel.assertQueue(queue, { 41 | durable: true 42 | }); 43 | channel.prefetch(1); 44 | 45 | console.log("Waiting for messages in %s", queue); 46 | channel.consume(queue, function(msg) { 47 | 48 | console.log("Received '%s'", msg.content.toString()); 49 | 50 | setTimeout(function() { 51 | channel.ack(msg); 52 | }, 1000); 53 | }); 54 | }); 55 | }); -------------------------------------------------------------------------------- /package-lock.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "node-queue", 3 | "version": "1.0.0", 4 | "lockfileVersion": 1, 5 | "requires": true, 6 | "dependencies": { 7 | "amqplib": { 8 | "version": "0.5.5", 9 | "resolved": "https://registry.npmjs.org/amqplib/-/amqplib-0.5.5.tgz", 10 | "integrity": "sha512-sWx1hbfHbyKMw6bXOK2k6+lHL8TESWxjAx5hG8fBtT7wcxoXNIsFxZMnFyBjxt3yL14vn7WqBDe5U6BGOadtLg==", 11 | "requires": { 12 | "bitsyntax": "~0.1.0", 13 | "bluebird": "^3.5.2", 14 | "buffer-more-ints": "~1.0.0", 15 | "readable-stream": "1.x >=1.1.9", 16 | "safe-buffer": "~5.1.2", 17 | "url-parse": "~1.4.3" 18 | } 19 | }, 20 | "bitsyntax": { 21 | "version": "0.1.0", 22 | "resolved": "https://registry.npmjs.org/bitsyntax/-/bitsyntax-0.1.0.tgz", 23 | "integrity": "sha512-ikAdCnrloKmFOugAfxWws89/fPc+nw0OOG1IzIE72uSOg/A3cYptKCjSUhDTuj7fhsJtzkzlv7l3b8PzRHLN0Q==", 24 | "requires": { 25 | "buffer-more-ints": "~1.0.0", 26 | "debug": "~2.6.9", 27 | "safe-buffer": "~5.1.2" 28 | } 29 | }, 30 | "bluebird": { 31 | "version": "3.5.5", 32 | "resolved": "https://registry.npmjs.org/bluebird/-/bluebird-3.5.5.tgz", 33 | "integrity": "sha512-5am6HnnfN+urzt4yfg7IgTbotDjIT/u8AJpEt0sIU9FtXfVeezXAPKswrG+xKUCOYAINpSdgZVDU6QFh+cuH3w==" 34 | }, 35 | "buffer-more-ints": { 36 | "version": "1.0.0", 37 | "resolved": "https://registry.npmjs.org/buffer-more-ints/-/buffer-more-ints-1.0.0.tgz", 38 | "integrity": "sha512-EMetuGFz5SLsT0QTnXzINh4Ksr+oo4i+UGTXEshiGCQWnsgSs7ZhJ8fzlwQ+OzEMs0MpDAMr1hxnblp5a4vcHg==" 39 | }, 40 | "core-util-is": { 41 | "version": "1.0.2", 42 | "resolved": "https://registry.npmjs.org/core-util-is/-/core-util-is-1.0.2.tgz", 43 | "integrity": "sha1-tf1UIgqivFq1eqtxQMlAdUUDwac=" 44 | }, 45 | "debug": { 46 | "version": "2.6.9", 47 | "resolved": "https://registry.npmjs.org/debug/-/debug-2.6.9.tgz", 48 | "integrity": "sha512-bC7ElrdJaJnPbAP+1EotYvqZsb3ecl5wi6Bfi6BJTUcNowp6cvspg0jXznRTKDjm/E7AdgFBVeAPVMNcKGsHMA==", 49 | "requires": { 50 | "ms": "2.0.0" 51 | } 52 | }, 53 | "inherits": { 54 | "version": "2.0.4", 55 | "resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.4.tgz", 56 | "integrity": "sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ==" 57 | }, 58 | "isarray": { 59 | "version": "0.0.1", 60 | "resolved": "https://registry.npmjs.org/isarray/-/isarray-0.0.1.tgz", 61 | "integrity": "sha1-ihis/Kmo9Bd+Cav8YDiTmwXR7t8=" 62 | }, 63 | "ms": { 64 | "version": "2.0.0", 65 | "resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz", 66 | "integrity": "sha1-VgiurfwAvmwpAd9fmGF4jeDVl8g=" 67 | }, 68 | "querystringify": { 69 | "version": "2.1.1", 70 | "resolved": "https://registry.npmjs.org/querystringify/-/querystringify-2.1.1.tgz", 71 | "integrity": "sha512-w7fLxIRCRT7U8Qu53jQnJyPkYZIaR4n5151KMfcJlO/A9397Wxb1amJvROTK6TOnp7PfoAmg/qXiNHI+08jRfA==" 72 | }, 73 | "readable-stream": { 74 | "version": "1.1.14", 75 | "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-1.1.14.tgz", 76 | "integrity": "sha1-fPTFTvZI44EwhMY23SB54WbAgdk=", 77 | "requires": { 78 | "core-util-is": "~1.0.0", 79 | "inherits": "~2.0.1", 80 | "isarray": "0.0.1", 81 | "string_decoder": "~0.10.x" 82 | } 83 | }, 84 | "requires-port": { 85 | "version": "1.0.0", 86 | "resolved": "https://registry.npmjs.org/requires-port/-/requires-port-1.0.0.tgz", 87 | "integrity": "sha1-kl0mAdOaxIXgkc8NpcbmlNw9yv8=" 88 | }, 89 | "safe-buffer": { 90 | "version": "5.1.2", 91 | "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.1.2.tgz", 92 | "integrity": "sha512-Gd2UZBJDkXlY7GbJxfsE8/nvKkUEU1G38c1siN6QP6a9PT9MmHB8GnpscSmMJSoF8LOIrt8ud/wPtojys4G6+g==" 93 | }, 94 | "string_decoder": { 95 | "version": "0.10.31", 96 | "resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-0.10.31.tgz", 97 | "integrity": "sha1-YuIDvEF2bGwoyfyEMB2rHFMQ+pQ=" 98 | }, 99 | "url-parse": { 100 | "version": "1.4.7", 101 | "resolved": "https://registry.npmjs.org/url-parse/-/url-parse-1.4.7.tgz", 102 | "integrity": "sha512-d3uaVyzDB9tQoSXFvuSUNFibTd9zxd2bkVrDRvF5TmvWWQwqE4lgYJ5m+x1DbecWkw+LK4RNl2CU1hHuOKPVlg==", 103 | "requires": { 104 | "querystringify": "^2.1.1", 105 | "requires-port": "^1.0.0" 106 | } 107 | } 108 | } 109 | } 110 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "node-queue", 3 | "version": "1.0.0", 4 | "description": "", 5 | "main": "index.js", 6 | "scripts": { 7 | "test": "echo \"Error: no test specified\" && exit 1" 8 | }, 9 | "author": "Swathi Prasad", 10 | "license": "MIT", 11 | "dependencies": { 12 | "amqplib": "^0.5.5" 13 | } 14 | } 15 | --------------------------------------------------------------------------------