New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

rabbit-worker

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

rabbit-worker

Very basic node module for creating and consuming from RabbitMQ work queues

latest
Source
npmnpm
Version
0.0.1
Version published
Maintainers
1
Created
Source

rabbit-worker

Very basic node module for creating and consuming from RabbitMQ work queues

Why?

Because I am writing a lot of small services that use this sort of queue. It is just a light rabbit.js wrapper (if for some weird reason you were hoping to use this project, I would instead you use that library directly) that defaults to persistant queues and automatically reconnects on connection failures.

Synopsis

var rabbitWorker = require('rabbit-worker');
var worker = new rabbitWorker.Worker('localhost', 'work_queue_1', function (message, ack) {
    console.log('got message', message);
    ack();					//important! Signals to the queue that the work has been completed
});
	
var tasker = new rabbitWorker.Tasker('localhost', 'work_queue_1');
if (tasker.isReady()) {
    tasker.publish('New message');
} else {
    tasker.once('ready', tasker.publish.bind(tasker, 'New message');
} 

TODO

  • Support for publisher confirms would be rad (I am currently living dangerously and not using them in the interest of code simplicity). Would require either a modification in the upstream rabbit.js library or that this module be converted to use amqplib as its upstream library directly (amqplib being the core module that rabbit.js relies on).

jsdoc-to-markdown output

rabbit-worker

Light wrapper over the rabbit module to easily create persistent workers and taskers.

Version: 0.0.1
Author: notnarb

rabbit-worker~Worker(rabbitserver, routingKey, workerFunction)

connects to the specified rabbitmq server as a worker for the specified routing key

Kind: inner method of rabbit-worker

ParamTypeDescription
rabbitserverStringThe hostname of the rabbit server to use
routingKeyStringthe routing key to listen on
workerFunctionfunctionthe function to call for each message. This function is called with 2 arguments: 'message', and 'ack'. Message is a string representation of the data passed and 'ack' is a function that must be called to acknowledge the function. Note: for simplicity: the function 'requeue' and 'discard' are omitted though they wouldn't be hard to add

Example

var worker = new Worker('localhost', 'work_queue_1', function (message, ack) {
    console.log('got message', message);
    ack();					//important! Signals to the queue that the work has been completed
})

rabbit-worker~Tasker(rabbitserver, routingKey) ⇐ event.EventEmitter

connects to the specified rabbitmq server as a publisher for the specified routing key. Emits a 'ready' event when it can start taking publish commands.

Kind: inner method of rabbit-worker
Extends: event.EventEmitter

ParamTypeDescription
rabbitserverStringThe hostname of the rabbit server to use
routingKeyStringthe routing key to listen on

Example

var tasker = new Tasker('localhost', 'work_queue_1');
if (tasker.isReady()) {
    tasker.publish('New message');
} else {
    tasker.once('ready', tasker.publish.bind(tasker, 'New message');
} 

tasker.publish(message)

Publishes a message to the queue

Kind: instance method of Tasker
Throws:

  • Error - if the queue is currently unavailable, this throws an error
ParamTypeDescription
messageStringmessage to publish to the queue

tasker.isReady() ⇒ Boolean

Checks to see if the tasker is currently connected to the queue

Kind: instance method of Tasker
Returns: Boolean - - true if currently can accept publish arguments

Keywords

rabbit

FAQs

Package last updated on 27 Apr 2015

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts