2.0.1 • Published 8 years ago

rrmq v2.0.1

Weekly downloads
1
License
ISC
Repository
-
Last release
8 years ago

RRMQ

Redis Reliable Message Queue

Build Status Coverage Status npm version

Install

This library currently requires node@>4.0.0 and npm@>3.0.0. If you're using node@4.*, you probably have npm@2.* installed, then you need to run the following command first.

npm install -g npm@3

If you've setup you environment properly, run

npm install rrmq bluebird tuid ioredis

while bluebird, tuid and ioredis are peer dependencies of this library

Introduction

This library implements a message queue over redis based on feature of BRPOPLPUSH and PUBLISH/SUBSCRIBE, and is written in Typescript.

There are three role in this system:

  • Producer

    An instance of producer may push message to queue

  • Watchdog

    A watchdog subscribe a specified channel to watch the status of consumers. If one consumer is down, the message was being processed by that consumer will be recovered.

    There is a separated project rrmq-watchdog that provides a standalone daemon that you can just run it for your convenience.

  • Consumer

    An instance of consumer await and pop message from the queue and meanwhile keeps heartbeat via publish message to a specified channel with a per-instance unique identifier to inform the watchdog that this instance is alive.

    If an instance died while processing a message. Watchdogs will notice that an instance has timed out and the message will be push back to the queue.

Example

  • watchdog.js
const { RedisQueueWatchdog } = require('rrmq');
new RedisQueueWatchdog({
  watchdogRedisHost: 'localhost', watchdogRedisPort: 6379,
  redisHost: 'localhost', redisPort:6379,
  watchdogTopic: 'test-watchdog'
})
.on('error', console.error)
.start();
  • consumer.js
const {RedisQueueConsumer} = require('rrmq');
new RedisQueueConsumer({
  watchdogRedisHost: 'localhost', watchdogRedisPort: 6379,
  redisHost: 'localhost', redisPort:6379,
  watchdogTopic: 'test-watchdog', queue: 'test-queue'
}).on('error', console.error)
.start(function(message) {
  return new Promise((done, fail)=> {
    // ...
  });
});
  • producer.js
const {RedisQueueProducer} = require('rrmq');
new RedisQueueConsumer({
  redisHost: 'localhost', redisPort:6379,
  queue: 'test-queue'
}).on('error', console.error)
.send('hello world message');
2.0.1

8 years ago

2.0.0

8 years ago

1.1.0

9 years ago

1.0.0

10 years ago

1.0.0-alpha2

10 years ago

1.0.0-alpha1

10 years ago

0.5.2

10 years ago

0.5.1

10 years ago

0.5.0

10 years ago

0.4.3

10 years ago

0.4.2

10 years ago

0.4.1

10 years ago

0.4.0

10 years ago

0.3.0-next

10 years ago

0.3.0

10 years ago

0.2.0

10 years ago

0.1.1

10 years ago

0.1.0

10 years ago