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

@nmq/q

v1.0.5

Published

A simple message queue system based on socket.io that allows you to build a queue server which can receive and broadcast categorized events, clients that can subscribe to said events, and publishers that can publish to the server.

Downloads

3

Readme

Simple Node Message Queue (@nmq)

A simple message queue system based on socket.io that allows you to build a queue server which can receive and broadcast categorized events, clients that can subscribe to said events, and publishers that can publish to the server.

Server Interface

Create a server to manage queues and events. Clients will eventually connect to the server to subscribe to these, and Publishers will be able to send messages.

  1. Set an environment variable PORT with the port number to listen on
  2. Start a server - Q.start()
  3. Create a new queue/category - const qname = new Q('name')
  4. Monitor events - qname.monitorEvent('event-name')

This example starts a Q server with 2 message queues (database and network) and will accept notifications of specific events for each of them.

server.js

const Q = require('@nmq/q/server');
Q.start();

const db = new Q('database');
db.monitorEvent('create');
db.monitorEvent('update');
db.monitorEvent('delete');

const network = new Q('network');
network.monitorEvent('attack');
network.monitorEvent('no-service');

Client/Subscriber Interface

Create any number of clients to connect to your queue server. Typically, your server will be running and deployed and clients can use this library to connect to that queue server and listen for events, running code (callbacks) when those events are fired.

Clients can connect to multiple queues and any number of events.

  1. Create an environment variable called Q_SERVER that contains the full URL and PORT of your running queue server
  2. Create new reference to any valid Queue
  3. Subscribe to any valid events in that Queue
  4. Perform any actions when those events occur
  5. Each event, when fired, will send data (payload) into the callback you define.

Here are a few simple examples

database-logger.js

This application will connect to the Queue server created above and respond to any delete or create events in the database queue.

const Q = require('@nmq/q/client');

const db = new Q('database');

db.subscribe('delete', (payload) => {
  console.log('delete happened', payload);
});

db.subscribe('create', (payload) => {
  console.log('create happened', payload);
});

network-logger.js

This application will connect to the Queue server created above and respond to the attack event in the network queue.

const Q = require('@nmq/q/client');

const network = new Q('network');

network.subscribe('attack', (payload) => {
  console.log('Shields Up!', payload);
});

Publisher Interface

Given a running server which exposes named queues and events and some separately running connected clients that are subscribed to those events, you can now use publish events into those queues from any application.

As these events fire, the server will "hear" them, reformat them, and then broadcast them out to all connected and subscribed clients who may then act upon the payload sent.

  1. Create an environment variable called Q_SERVER that contains the full URL and PORT of your running queue server
  2. Call the publish method on the queue server with the following parameters:
  • Queue Name
  • Event Name
  • Payload - Can be of any type (string, array, object, boolean)
const Q = require('@nmq/q/client');

Q.publish('database', 'delete', {id:77});
Q.publish('database', 'create', {id:99,name:'John'});
Q.publish('network', 'attack', {type: 'DDOS',source:'Russia'});

Dependencies