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

crimsonq

v0.5.1

Published

[![buddy pipeline](https://app.buddy.works/ywadi85/crimsonq/pipelines/pipeline/373325/badge.svg?token=463c4f343893f85c5056a16ba6da1379079553b6b7a950b7ba9d643591fcb0d2 "buddy pipeline")](https://app.buddy.works/ywadi85/crimsonq/pipelines/pipeline/373325) !

Downloads

34

Readme

CrimsonQ NodeJS Client Library

buddy pipeline GitHub release (latest by date) GitHub

A Multi Consumer per Message Queue with persistence and Queue Stages.

crimsonq

CrimsonQ is a high performance Multi Consumer per Message with persistence and Queue Stages written in pure go. The idea is to allow consumers to never miss out on messages from a traditional pub/sub and at the same time be able to manage messages like in a queue with stages (pending, active, delayed, failed, comapleted)

You can get CrimsonQ from the github repo here and then use this client in your nodejs application easily.

Installation

Simply install it from npm using

$ npm install crimsonq --save

Now you can use the library to connect with crimsonq either as a producer or consumer.

Usage

Once you have installed the module you can then require it to use it in your code, whether as a producer or consumer you need to require it as follows; let CrimsonQ = require("./lib/crimsonq"); Once required you will need to setup the connection as follows;

//Initiate an Instance Consumer 
let  CQ = new  CrimsonQ({
    port:  9001, // Redis port
    host:  "127.0.0.1", // Redis host
    password:  "crimsonQ!",
});
//Connect and await for the connect 
await CQ.connect();

As a Producer

To use the client as a Producer all you need to do is create a new producer for the client instance as follows;

let producer = CQ.Producer();

Then you can use the producer to publish messages. There are 2 ways you can publish messages, either directly to a consumer on its id, or to multiple consumers through a MQTT like topic, see MQTT topic matching for details. Below are the commands that can be used against the producer

producer.pushToConsumer(consumerId, message)

Send messages to a consumer's queue directly into its queue and will be in the pending state awaiting to be pulled.

Kind: instance method of Producer

| Param | Type | Description | | --- | --- | --- | | consumerId | string | The consumer Id that will recieve the message | | message | Object | The message object that needs to be pushed to consumers |

producer.pushToTopic(topic, message) Send message to the topic queue and this will provide a message copy for each consumer in its queue.

Kind: instance method of Producer

| Param | Type | Description | | --- | --- | --- | | topic | string | The topic that will be used to send to consumers listening to the topic. The topic can have MQTT style wildcards. | | message | Object | The message object that needs to be pushed to consumers |

As a Consumer

The consumer will read messages out of its own queue, all the messages that have been sent to the consumer will be accessible through the consumer part of the library. To get started you will need to setup the consumer as follows;

let  consumer = CQ.Consumer("I_WANT_MESSAGES");
await consumer.init(["/path1/sub2", "/path2/#"], 1);

You can setup the consumer by creating an instance and giving it a unique ID, make sure that each consumer you have has a different ID, if you need 2 consumers to read the same messages, create the consumer twice with different IDs but same topics, then push a message to a topic that matches both consumers. A visual explanation can be seen below; enter image description here

Once you have gotten the consumer setup now its a matter of waiting for messages

consumer.events.on("message", async function (msg) {
        try {
	         //DO something with the msg data here, when done make sure to call done to tell
	         //the queue that you have consumed it properly.  
             await msg.done()
        } catch (e) {
            //If the above failes, you can call msg.fail and send the reason of failure back 
            //to the queue. 
            msg.fail(e.message)
        }
    })

Auto-reconnect

This client is based on ioredis and has the same methodology, if a connection is interrupted it will reconnect and also be up and functional. The client will also start to pull the messages that the client missed when was online.

Examples

You can find examples in the repos example folder.