remq

Redis-backed durable message queue

Remq-node

A Node.js client library for Remq, a Redis-based protocol for building fast, persistent pub/sub message queues.

NOTE: In early-stage development, API not locked.

npm install remq

Producer:

var remq = require('remq').createClient();
 
var message = { event: 'signup', account_id: 694 };
 
remq.publish('events.accounts', message, function(errid) {
  if(err) { return console.error(err); }
  console.log("Published message to the 'events.accounts' channel with id: " + id);
});

Pub/sub consumer (messages lost during failure):

var remq = require('remq').createClient();
 
remq.on('message', function(channelmessageid) {
  console.log("Received message on the 'events.accounts' channel with id: " + id);
  console.log("Account just signed up: " + message.account_id);
});
 
remq.subscribe('events.accounts');

Polling consumer with cursor (resumes post-failure):

var remq = require('remq').createClient()
  , cursorKey = remq.key('cursor:consumer-1');
 
remq.on('message', function(channelmessageid) {
  console.log("'" + channel + '.' + id + "':");
  console.log(require('util').inspect(message) + '\n');
  count++;
});
 
// retrieve cursor and resume subscription at the cursor 
remq.redis.get(cursorKey, function(errcursor) {
  remq.subscribe('events.accounts', { cursor: cursor, interval: 1000 });
});
 
// update cursor using the `cursor` event (emitted after poll) 
remq.on('cursor', function(cursor) { remq.redis.set(cursorKey, cursor); });

Purging old messages:

 
// purge old messages, keeping the last 1 million 
remq.purge('events.accounts', { keep: 10000000 }, function(errnum) {
  if(err) { return console.error(err); }
  console.log("purged " + num + " messages from 'events.accounts'");
});