Git Product home page Git Product logo

jackrabbit's Introduction

Jackrabbit

Simple AMQP / RabbitMQ job queues for node

var queue = jackrabbit('amqp://localhost');

queue.on('connected', function() {
  queue.create('jobs.greet', { prefetch: 5 }, onReady);

  function onReady() {
    queue.handle('jobs.greet', onJob);
    queue.publish('jobs.greet', { name: 'Hunter' });
  }

  function onJob(job, ack) {
    console.log('Hello, ' + job.name);
    ack();
  }
});

Installation

npm install --save jackrabbit
var jackrabbit = require('jackrabbit');

Use

First, create a queue and connect to an amqp server:

var queue = jackrabbit(amqp_url, prefetch)
  • amqp_url: eg, 'amqp://localhost'
  • prefetch: messages to prefetch (default = 1)

create

Create (or assert) a queue.

queue.create(name, options, callback)
  • name: name of the queue (eg, 'jobs.scrape')
  • options: object with...
    • durable (Boolean, default = true)
    • prefetch (Number, default = 1)
  • callback: callback function for result (err, queue_instance, queue_info)

destroy

Destroy a queue.

queue.destroy(name, callback)
  • name: name of the queue
  • callback: callback for result (err, destroyed)

You can destroy queues that exist or don't exist; if you try to destroy a queue that doesn't exist, destroyed = false. If a queue was destroyed, destroyed = true.

publish

Publish a job to a queue.

queue.publish(name, message)
  • name: name of the queue
  • message: an Object that is your message / job to add to the queue

handle

Start handling jobs in a queue.

queue.handle(name, handler)
  • name: name of the queue
  • handler: a Function to receive jobs (job, ack)

Jobs must be acknowledged. You can either ack immediately (so all jobs will be run at most once) or you can ack on job completion (so all jobs will run at least once).

ignore

Stop handling a queue.

queue.ignore(name)
  • name: name of the queue

purge

Purge a queue.

queue.purge(name, callback);
  • name: name of the queue
  • callback: Function to be called on completion with (err, countOfPurgedMessages)

Tests

  1. Run rabbit on 'amqp://localhost'
  2. npm test

jackrabbit's People

Contributors

hunterloftis avatar pwmckenna avatar wiktorwojcikowski avatar

Watchers

 avatar  avatar

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.