Skip to content
This repository has been archived by the owner on May 15, 2024. It is now read-only.
/ wrabbit Public archive
forked from nikostoulas/jackrabbit-2

Simple AMQP / RabbitMQ job queues for node based on amqplib

Notifications You must be signed in to change notification settings

Workable/wrabbit

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

72 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

WRabbit (based on jackrabbit )

Simple AMQP / RabbitMQ job queues for node

var queue = wrabbit('amqp:https://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

not in npm -- you will have install it through git

Add in package.json the bellow dependency:

"wrabbit": "git:https://github.com/workable/wrabbit.git#0.0.1"

and then run

npm install
var wrabbit = require('wrabbit');

Use

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

var queue = wrabbit(amqp_url, prefetch)
  • amqp_url: eg, 'amqp:https://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:https://localhost'
  2. npm test

About

Simple AMQP / RabbitMQ job queues for node based on amqplib

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages

  • JavaScript 100.0%