simple-amqplib-wrapper
Utilities for RabbitMQ
Last updated 2 years ago by nishant-jain-94 .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install simple-amqplib-wrapper 
SYNC missed versions from official npm registry.

Simple-Amqplib-Wrapper travis dependencies Coverage Status

NPM

Simple Amqplib Wrapper is a wrapper around amqplib abstracting all the complexity. Currently works only on Node v8.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();

Current Tags

  • 2.0.3                                ...           latest (2 years ago)

9 Versions

  • 2.0.3                                ...           2 years ago
  • 2.0.2                                ...           2 years ago
  • 2.0.1                                ...           2 years ago
  • 1.1.1                                ...           2 years ago
  • 1.1.0                                ...           2 years ago
  • 1.0.3                                ...           2 years ago
  • 1.0.1-rc.1                                ...           2 years ago
  • 1.0.0-rc.1                                ...           2 years ago
  • 1.0.1                                ...           2 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 4
Last Day 0
Last Week 4
Last Month 23
Dependencies (8)
Dev Dependencies (7)
Dependents (0)
None

Copyright 2014 - 2016 © taobao.org |