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

@superbalist/js-pubsub-manager

v3.0.1

Published

A manager & factory for the js-pubsub package.

Downloads

15

Readme

@superbalist/js-pubsub-manager

A manager & factory for the js-pubsub package.

Author Build Status Software License NPM Version NPM Downloads

This package adds a factory and manager on top of the js-pubsub package.

The following adapters are supported:

  • Local
  • /dev/null
  • Redis
  • Google Cloud
  • HTTP

Installation

npm install @superbalist/js-pubsub-manager

The package has a default configuration which uses the following environment variables.

PUBSUB_CONNECTION=redis

REDIS_HOST=localhost
REDIS_PORT=6379

GOOGLE_CLOUD_PROJECT_ID=your-project-id-here
GOOGLE_APPLICATION_CREDENTIALS=path/to/your/gcloud-key.json
GOOGLE_CLOUD_CLIENT_IDENTIFIER=null

HTTP_PUBSUB_URI=null
HTTP_PUBSUB_SUBSCRIBE_CONNECTION=redis

Usage

'use strict';

let pubSubManager = require('@superbalist/js-pubsub-manager');
let PubSubManager = pubSubManager.PubSubManager;
let PubSubConnectionFactory = pubSubManager.PubSubConnectionFactory;
let config = pubSubManager.config;

// add a custom connection to the config
config.connections.my_connection = {
  'driver': 'redis',
  'host': '192.168.0.1',
  'port': 6379,
  'db': 0
}

// create the connection manager
let factory = new PubSubConnectionFactory();
let manager = new PubSubManager(factory, config);

// get the default connection
let connection = manager.connection();

// publish a message
connection.publish('my_channel', {"first_name":"Matthew"});

// publish multiple messages to a channel
let messages = [
  'message 1',
  'message 2',
];
connection.publishBatch('my_channel', messages);

// subscribe to a channel
connection.subscribe('my_channel', (message) => {
  console.log(message);
  console.log(typeof message);
});

// publish a message over a custom or named connection
manager.connection('my_connection').publish('Hello World!');

Adding a Custom Driver

Please see the js-pubsub documentation Writing an Adapter.

To include your custom driver, you can call the extend() function.

'use strict';

let pubSubManager = require('@superbalist/js-pubsub-manager');
let PubSubManager = pubSubManager.PubSubManager;
let PubSubConnectionFactory = pubSubManager.PubSubConnectionFactory;
let config = pubSubManager.config;

// create the connection manager
config.connections.custom_driver = {
  // add custom config here
};
let factory = new PubSubConnectionFactory();
let manager = new PubSubManager(factory, config);

manager.extend('custom_driver', (config) => {
  // your callable must return an object which implements the https://github.com/Superbalist/js-pubsub/blob/master/src/PubSubAdapterInterface.js interface.
  return new MyCustomPubSubDriver(config);
});

// get an instance of your connection using a custom driver
let connection = manager.connection('custom_driver');