rrmq
Redis Reliable Message Queue
Last updated a year ago by thynson .
ISC · Original npm · Tarball
$ cnpm install rrmq 
SYNC missed versions from official npm registry.

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

where bluebird and tuid 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.

  • 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');

Use with typescript

The typing file of this library can is placed on node_modules/rrmq/built/index.d.ts.

Maintainers (1)
Downloads
Today 0
This Week 0
This Month 2
Last Day 0
Last Week 2
Last Month 0
Dependencies (0)
None
Dev Dependencies (12)
Dependents (1)

Copyright 2014 - 2016 © taobao.org |