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

process-pubsub

v1.0.2

Published

A tiny library that enables node applications to publish events to one multiple interested consumers asynchronously, without coupling the producers to the consumers

Downloads

3

Readme

Process PubSub

A tiny library that enables node applications to publish events to one multiple interested consumers asynchronously, without coupling the producers to the consumers.

Works only on single process, to provide effective way to decouple producers from consumers

Node Version npm version Build Status Coverage Status License

How Process PubSub works:

Installation

npm install process-pubsub --save

Features

  • Simplicity & flexibility
  • Light weight

Usage

Channels & Topics

  • Channel: is a logical container used to send and receive messages, publishing/receiving messages should be through a channel
  • Topic: is a logical container within channel used to send and receive messages, publishing/receiving messages should be through a topic registered within a channel

Subscription

subscribe function can be used to subscribe to one or more channels and topics, through Subscribtion object:

Subscription:

  • channel String Channel name
  • topic String Topic name
  • once Boolean, optional, default = fasle Get notified about specific event only once
  • callback Function(message, metadata) Callback function will be invoked when message published to a channel and/or topic

Simple subscription:

import {PubSub} from 'process-pubsub';

const pubsub = new PubSub();
pubsub.subscribe({
    channel: 'orders',
    topic: 'created',
    callback: (message, metadata) => {
        console.log(message);
    }
});

Subscription to get notified for all messages in specific channel is also possible using * with topic field:

import {PubSub} from 'process-pubsub';

const pubsub = new PubSub();
pubsub.subscribe({
    channel: 'orders',
    topic: '*',
    callback: (message, metadata) => {
        console.log(message);
    }
});

Subscribe to all messages published to any topic under channel "orders", so callback handler will be call if we publish messages to "create", "updated" topic for example or any other topic under "orders" channel

Once subscription

Setting once field to true will notify the subscriber with the event for only one-time, after that the subscription will be removed.

import {PubSub} from 'process-pubsub';

const pubsub = new PubSub();
pubsub.subscribe({
    channel: 'orders',
    topic: 'created',
    once: true,
    callback: (message, metadata) => {
        console.log(message);
    }
});

Message metadata

callback function will also receive metadata object with message, which includes the following fields:

  • channel The current message destination channel
  • topic The current message destination topic (If subscriber is listening to all topic using * under specific channel, metadata will be very useful)

Publishing

We can publish directly to specific channel and topic:

import {PubSub} from 'process-pubsub';
const pubsub = new PubSub();
pubsub.publish('orders', 'created', {id: 1, amount: 120});
  • This message will be received by all subscribers of channel orders and topic created
  • This message will be received also by subscribers of channel orders and topic *

We can publish to all topics registered within a specific channel, by using * for topic

import {PubSub} from 'process-pubsub';
const pubsub = new PubSub();
pubsub.publish('orders', '*', {id: 1, amount: 120});

This message will be received by all subscribers of channel orders, whatever the topic the subscriber is registered with

Synchronous Request-Reply

Synchronous Request-Reply style is also possible using publishAndGetReply function, we can publish message and wait for response from first register subscriber, or break the operation if timeout exceeded.

import {PubSub} from 'process-pubsub';

const pubsub = new PubSub();
const response = await pubsub.publishAndGetReply('orders', 'created', {id: 1, amount: 120});

License

MIT