Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/nishant-jain-94/simple-amqplib-wrapper
https://github.com/nishant-jain-94/simple-amqplib-wrapper
Last synced: 5 days ago
JSON representation
- Host: GitHub
- URL: https://github.com/nishant-jain-94/simple-amqplib-wrapper
- Owner: nishant-jain-94
- License: mit
- Created: 2017-09-05T09:39:20.000Z (about 7 years ago)
- Default Branch: master
- Last Pushed: 2017-10-10T20:19:08.000Z (about 7 years ago)
- Last Synced: 2024-10-06T18:07:44.432Z (about 1 month ago)
- Language: HTML
- Size: 85 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Simple-Amqplib-Wrapper [![travis](https://travis-ci.org/nishant-jain-94/simple-amqplib-wrapper.svg?branch=dev)](https://travis-ci.org/nishant-jain-94/simple-amqplib-wrapper) [![dependencies](https://david-dm.org/nishant-jain-94/simple-amqplib-wrapper.svg)](https://david-dm.org) [![Coverage Status](https://coveralls.io/repos/github/nishant-jain-94/simple-amqplib-wrapper/badge.svg?branch=master)](https://coveralls.io/github/nishant-jain-94/simple-amqplib-wrapper?branch=master)
[![NPM](https://nodei.co/npm/simple-amqplib-wrapper.png)](https://nodei.co/npm/simple-amqplib-wrapper/)[Simple Amqplib Wrapper](https://www.npmjs.com/package/simple-amqplib-wrapper) is a wrapper around [amqplib](https://www.npmjs.com/package/amqplib) abstracting all the complexity. Currently works only on [Node v8.0](https://nodejs.org/en/blog/release/v8.0.0/)
## Amqplib vs Simple-Amqplib-Wrapper ?
### Using Amqplib you do this
```
var q = 'tasks';
function bail(err) {
console.error(err);
process.exit(1);
}
// Publisher
function publisher(conn) {
conn.createChannel(on_open);
function on_open(err, ch) {
if (err != null) bail(err);
ch.assertQueue(q);
ch.sendToQueue(q, new Buffer('something to do'));
}
}
// Consumer
function consumer(conn) {
var ok = conn.createChannel(on_open);
function on_open(err, ch) {
if (err != null) bail(err);
ch.assertQueue(q);
ch.consume(q, function(msg) {
if (msg !== null) {
console.log(msg.content.toString());
ch.ack(msg);
}
});
}
}
require('amqplib/callback_api')
.connect('amqp://localhost', function(err, conn) {
if (err != null) bail(err);
consumer(conn);
publisher(conn);
});
```### With [Simple-Amqplib-Wrapper]() it's super simple
```
const Amqp = require('simple-amqplib-wrapper');
const amqp = new Amqp('amqp://localhost');const q = 'tasks';
const testTask = { message: 'First Task' };const publisher = () => {
return amqp.sendToQueue(q, testTask);
};const consumer = () => {
amqp.consumeStream(q).take(1).each((msg) => {
console.log(msg);
amqp.acknowledge(msg);
});
};publisher();
consumer();
```