A High-Performance Redis Simple Message Queue for Node.js
Key Features
- 🚀 High-performance message processing
- 🔄 Flexible producer/consumer model with multi-queue producers and consumers
- 🔀 Different exchange types (Direct, Topic, FanOut) for publishing messages to one or multiple queues
- 📬 Two delivery models (Point-2-Point and Pub/Sub) with reliable delivery and configurable retry modes
- 📊 Three queuing strategies (FIFO, LIFO, Priority Queues)
- 🧵 Message handler worker threads for sandboxing and performance improvement
- ⏱️ Message expiration and consumption timeout
- 🚦 Queue rate limiting for controlling message consumption rates
- 🕰️ Built-in scheduler for delayed message delivery and repeating messages
- 🌐 RESTful API and Web UI for interacting with the message queue
- 📦 Support for ESM and CJS modules
Use Cases
- Managing background tasks, such as email sending or data processing.
- Efficiently scheduling and retrying tasks.
- Communication between multiple services in microservices architectures.
- Handling real-time events in gaming, IoT, or analytics systems.
Installation
To get started with RedisSMQ, you can install the library using npm:
npm i redis-smq@rc
Don't forget to install a Redis client. Choose either node-redis or ioredis:
npm install @redis/client
# or
npm install ioredis
Configuration
Set up the RedisSMQ configuration during your application bootstrap:
'use strict';
const { Configuration, ERedisConfigClient } = require('redis-smq');
const config = {
redis: {
// Using ioredis as the Redis client
client: ERedisConfigClient.IOREDIS,
// Add any other ioredis options here
options: {
host: '127.0.0.1',
port: 6379,
},
},
};
Configuration.getSetConfig(config);
Usage
Here's a basic example to create a queue, produce a message, and consume it:
// Creating a queue
const queue = new Queue();
queue.save('my_queue', EQueueType.LIFO_QUEUE, EQueueDeliveryModel.POINT_TO_POINT, (err) => {
if (err) console.error(err);
});
// Producing a message
const msg = new ProducibleMessage();
msg.setQueue('my_queue').setBody('Hello Word!');
producer.produce(msg, (err, ids) => {
if (err) console.error(err);
else console.log(`Produced message IDs are: ${ids.join(', ')}`);
});
// Consuming a message
const consumer = new Consumer();
const messageHandler = (msg, cb) => {
console.log(msg.body);
cb(); // Acknowledging
};
consumer.consume('my_queue', messageHandler, (err) => {
if (err) console.error(err);
});
Documentation
For more information, visit the RedisSMQ Docs.
Contributing
Interested in contributing to this project? Please check out our CONTRIBUTING.md.
License
RedisSMQ is released under the MIT License.