Big News: Socket raises $60M Series C at a $1B valuation to secure software supply chains for AI-driven development.Announcement
Sign In

redmq

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

redmq

simple message queue based on Redis streams

latest
Source
npmnpm
Version
0.0.8
Version published
Weekly downloads
6
100%
Maintainers
1
Weekly downloads
 
Created
Source

RedMQ

simple message queue based on Redis streams

Only Redis 5.x and above support stream

Getting Started

npm install redmq
# yarn add redmq
# pnpm add redmq

Usage

import { RedMQ } from 'redmq'


const redmq = new RedMQ('id')

// producer
const producer = redmq.producer()
producer.send('my-topic', { body: 'body content' })

// consumer
const consumer = redmq.consumer(
  'group',
  ['topic1', 'topic2'],
  async (msg) => {
    // handle the message
  }
)

consumer.start()

Topic

The term topic used here is actually the key of stream in Redis, multiple topics means multiple streams.

Producer

Producer is simple and straightforward, the maxLen options is used for a capped stream, that means the messages will not exceed the maxLen(it's not accurate, since  using almost exact trimming (the ~ argument)).

Consumer

Consumers use pull strategy for fetching new messages, for the messages that are not processed successfully will be retried after a specific time.

Options:

  • timeout: message will be redelivered if timeout is reached

  • batchSize: how many messages will be fetched in one time for a consumer

  • maxDeliverTimes: the message will be abandon if the max deliver times reached

Connection

Each producer and consumer will share the same Redis connection by default, if you want the producer or consumer to use an individual connection, just set shareConnection to false, then a new connection will created for it.

FAQs

Package last updated on 29 Dec 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts