Coder Social home page Coder Social logo

node-queuefy's Introduction

node-queuefy

A simple, performant and straight-forward queue system for Node.js

Installation

$ npm install node-queuefy

Queue server

var queuefy = require('node-queuefy');
var server = new queuefy.Server({
   port: 5678
});

server.on('enqueue', function(item){
   console.log("Enqueued item: ", item);
}).on('dequeue', function(item) {
   console.log("Dequeued item: ", item);
});
server.listen(function() {
   console.log('Listening on port ' + server.config.port);
});

Worker example for queueing / dequeue

var queuefy = require('node-queuefy');
var worker = new queuefy.Worker({
   host: '127.0.0.1',
   port: 5678
});
worker.connect(function(){
   console.log('Connected to the queue server');
   // Enqueue a string item for processing, with a confirmation callback
   worker.enqueue("item", function(err) {
      if(err) console.log(err);
   });
   // Enqueue an object with no confirmation callback, used for fast enqueueing
   worker.enqueue({
      'this': 'is',
      'an': 'item'
   });

   // Dequeue the last enqueued item.
   worker.dequeue(function(err, item) {
      if(err) return console.log(err);
      console.log('Dequeued for processing: ', item);
   });
   // Dequeue the last 5 items enqueued in the list
   worker.dequeue(5, function(err, items) {
      if(err) return console.log(err);
      console.log('Dequeued ' + items.length + ' items');
   });
});
worker.on('error', function(e) {
   console.log('Whoops, got an error: ', e);
});

Benchmarking

I have set up the queue server on one 5$ DigitalOcean droplet, and 50 worker clients which managed to push 30.000 items/second, with no callback confirmation. Tested with callback confirmations, the rate dropped at about 3.000 items/second

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.