A simple high-performance Redis message queue for Node.js.
RedisSMQ
RedisSMQ is a Node.js library for queuing messages (aka jobs) and processing them asynchronously with consumers. Backed by Redis, it allows scaling up your application with ease of use.
Features
- High-performance message processing.
- Flexible Producer/Consumer model which offers Multi-Queue Producers & Multi-Queue Consumers, focuses on simplicity and without tons of features. This makes RedisSMQ an ideal message broker for microservices-based applications.
- In case of failures, while delivering or processing a message, RedisSMQ can guaranty that the message is not lost and that it is redelivered at-least-once. When configured to do so, RedisSMQ can also ensure that the message is delivered at-most-once.
- RedisSMQ offers different exchange types: Direct Exchange, Topic Exchange, and FanOut Exchange for publishing a message to one or multiple queues.
- 3 queuing strategies that you may use depending on your needs and requirements: FIFO queues, LIFO queues, and Reliable Priority Queues.
- A message can be set to expire if it has not been delivered within a given amount of time. Consumption timeout allows canceling a message consumption if a consumer did not acknowledge the message for a period of time.
- Queue Rate Limiting which allows to control the rate at which the messages are consumed from a given queue.
- Builtin message scheduler allowing to delay a message, to deliver a message for N times with an optional period between deliveries, or simply to schedule message delivery using CRON expressions.
- Multiplexing: A feature which allows message handlers to use a single redis connection to dequeue and consume messages.
- An HTTP interface is provided to interact with the MQ. RedisSMQ can be managed also from your web browser.
- Depending on your preferences, RedisSMQ can use either node-redis v3, node-redis v4, or ioredis.
- RedisSMQ is highly optimized, implemented using pure callbacks, with small memory footprint and no memory leaks. See Callback vs Promise vs Async/Await benchmarks.
- Both ESM & CJS modules are supported.
RedisSMQ Use Case: Multi-Queue Producers & Multi-Queue Consumers
What's new?
:rocket: RedisSMQ v8 is coming soon!
Installation
Currently, RedisSMQ is going under heavy development. Pre-releases at any time may introduce new commits with breaking changes. To view the latest release reference see RedisSMQ v7.2.3
npm i redis-smq@rc
Considerations:
- Minimal Node.js version is >= 18 (RedisSMQ is tested under current active LTS and maintenance LTS Node.js releases).
- Minimal Redis server version is 4.0.0.
Usage
RedisSMQ provides 3 classes in order to work with the message queue: ProducibleMessage
, Producer
, and Consumer
.
Producers and consumers exchange data using one or multiple queues that may be created using the Queue Class.
A queue is responsible for holding messages which are produced by producers and are delivered to consumers.
Creating a queue
const { Queue, EQueueType } = require('redis-smq');
const queue = new Queue();
queue.save('my_queue', EQueueType.LIFO_QUEUE, (err) => console.log(err));
Producing a message
const { Producer, ProducibleMessage } = require('redis-smq');
const producer = new Producer();
const msg = new ProducibleMessage();
msg.setQueue('my_queue').setBody('Hello Word!')
producer.produce(msg, (err) => console.log(err));
Consuming a message
const { Consumer } = require('redis-smq');
const consumer = new Consumer();
const messageHandler = (msg, cb) => {
console.log(msg.getBody());
cb();
}
consumer.consume('my_queue', messageHandler, (err) => console.log(err));
Documentation
See RedisSMQ Docs for more details.
Contributing
So you are interested in contributing to this project? Please see CONTRIBUTING.md.
License
MIT