Coder Social home page Coder Social logo

redmq's Introduction

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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.