Skip to content

A simple high-performance Redis message queue for Node.js.

License

Notifications You must be signed in to change notification settings

weyoss/redis-smq

Repository files navigation

RedisSMQ

A High-Performance Redis Simple Message Queue for Node.js

Build Code Quality Code Coverage Latest Release Downloads

Key Features

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.