Fast message processing queue backed up by redis and nodejs.
npm install redisq
Sample code that shows how to create a new task and push it to the queue.
var redisq = ;redisqoptionsredis:host: 'example.com'port: 6379;var queue = redisq;var task = foo: bar: true data: 10 20;queue;
By default queue tries to establish a connection with redis server running on the localhost.
Otherwise you can change this behaviour by using
redisqoptionsredis:host: 'example.com'port: 6379;// alternatively you can provide custom redis clientvar myClient = ;redisqoptionsredis: myClient;
To process your messages you have to create one or multiply clients that will 'listen' for new tasks and handle them in appropriate way.
var redisq = ;redisqoptionsredis:host: 'example.com'port: 6379;var queue = redisqconcurrency = 16;queue;
Please note that you have to call
cb function and pass error as the first argument
(if there are any).
Changing tasks while processing
The second argument is optional data that will replace the current task (if it fails) with the new data. This can be used for keep track of the number of tries, or updating the data to be worked on based on certain fail conditions.
var request = ;queue;
If task failed, it will be pushed back to the queue for another attempt.
Otherwise you can set a
retry flag to false so failed tasks will be ignored.
var queue = redisq;queueretry = false;
Pause / resume processing
Optionally, you can pause the queue in the event your downstream prerequisites have
failed. You can pause processing anytime by calling
queue.pause(). Once the queue
is ready to proceed, call
var queue = redisq;queue;
Module has a useful frontend that you can use for monitoring of the queue status. By default queue saves statistics to redis once a minute and stores it for 14 days. To run it use the following code:
var frontend = ;frontend;
In case if you want to customize host, port or provide a callback, you can pass additional arguments to the
var frontend =options =redis:host: 'example.com'port: 6379;// frontend.listen(port, [hostname], [options], [callback])frontend;
Frontend uses express framework and exposes
app for customization, for example adding basic authentication:
var frontend =express = ;frontendapp;frontend;
Also you can setup your monitoring tools to check the queue health by using special
$ curl ""
This method returns
200 if everything is fine, otherwise status would be
500. The check fetches
last 15 minutes of history and detects if your workers can't handle all tasks you create.