npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

redismb

v1.0.3

Published

Simplifying microservices communication with efficient event-driven architecture powered by Redis Streams

Downloads

160

Readme

redismb

npm npm GitHub license npm

Welcome to redismb! 🚀

This guide will help you get started with setting up a Redis message broker system based on Redis Streams using this powerful tool. Below are step-by-step instructions on initializing the Redis connection, creating subscribers and publishers, handling rejected messages, and more.

[!NOTE] Make sure to replace placeholders such as 'channel', 'group', 'action', and data with your actual channel names, consumer groups, actions, and data objects.

Installation

You can install the redismb library using npm:

npm install redismb

Getting Started

Now let's dive into how you can use the redismb library in your Node.js applications.

Initialize the Redis Connection

To start using the library, you need to initialize the Redis connection. Here's how you can do it:

import redismb, { Subscriber, Publisher } from 'redismb';
await redismb.bootstrap('redis://localhost:6379');

Create a Subscriber

Subscribers listen for messages on specific channels and consume them while assigned to a consumer group. You can create a subscriber instance like this:

const subscriber = new Subscriber({ channels: ['channel'], group: 'group' });
subscriber.subscribe(async ({ channel, action, data, id }) => {
  // Process the received message...
});

Create a Publisher

Publishers send messages to specific channels. Here's how you can create a publisher instance and publish a message:

const publisher = new Publisher({ channel: 'channel' });
const data = { foo: 'bar' };
await publisher.publish('action', data);

Unsubscribe and Stop the Redis Connection

When you're done with streaming messages, you can unsubscribe from channels and stop the Redis connection:

await subscriber.unsubscribe();
await redismb.stop();

Handle Rejected Messages

In case of rejected messages, you can read and reprocess them using the following methods:

await redismb.readRejectedMessages({ ids, from, to, action });
await redismb.reprocessRejectedMessages({ messages, ids, from, to, action });

Parameters:

  • ids (optional): An array of message IDs to filter rejected messages.
  • from (optional): The start date from which to filter rejected messages.
  • to (optional): The end date until which to filter rejected messages.
  • action (optional): Parameter used to filter rejected messages by a specific action.

If none of the previous parameters are defined, all messages will be retrieved.

  • messages(optional): Array of objects with optional properties: id, channel, group, and data. These properties are intended to republish the rejected messages (filtered by the previous parameters) to a different channel than they had, to a different consumer group from the one that revoked them, or with new properties in the data object.

Conclusion

That's it! You've learned how to set up a Redis message broker system using the redismb library. Feel free to explore more features and customize it according to your project's needs.

You can also find here a cool cheatsheet ❤️ about Redis Streams.

Happy messaging! 📨