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

strong-pubsub-modify

v1.0.2

Published

Reliable PubSub

Downloads

2

Readme

Installation

$ npm install strong-pubsub

Use

NOTE: until version 1.0.0 the API may change!

var Client = require('strong-pubsub');
var Adapter = require('strong-pubsub-mqtt');

// two clients connecting to the same broker
var siskel = new Client({host: 'my.message-broker.com', port: 3000}, Adapter);
var ebert = new Client({host: 'my.message-broker.com', port: 3000}, Adapter);

siskel.subscribe('movies');
siskel.on('message', function(topic, msg) {
 console.log(topic, msg.toString()); // => movies birdman
});

ebert.publish('movies', 'birdman');

Client (strong-pubsub)

The Client class provides a unified pubsub client in Node.js and browsers. It supports subscribing to topics or topic patterns (topics and wildcards). Clients can connect to brokers or bridges that support the client.adapter’s protocol.

Bridge (strong-pubsub-bridge)

In some cases, clients should not connect directly to a message broker. The Bridge class allows you to create a bridge between a client connecting to your node.js server and a broker. It supports hooks for injecting logic before the bridge performs an action on behalf of the client. Hooks allow you to implement client authentication and client action (publish, subscribe) authorization using vanilla node.js (usually in place of broker specific access controls and authentication).

Bridges also allow clients to connect to brokers over a protocol that the broker may not support. For example, a client can connect to the bridge using one protocol (eg. MQTT) and the bridge will connect to the broker using another (eg. Redis or STOMP).

Bridge

Note: It is not possible to guarantee all features when bridging connections of one protocol to a broker that speaks another protocol. For example MQTT quality of service (options.qos) will be not be guaranteed when a bridge is accepting MQTT protocol connections and bridging to a redis broker.

Creating a bridge

Here is an example setting up a bridge. This would bridge messages between MQTT clients and a RabbitMQ server.

// my-bridge-server.js
var server = require('./my-existing-server');

var Adapter = require('strong-pubsub-mqtt');
var client = new Client('mqtt://my.mosquitto.org', Adapter);
var Connection = require('strong-pubsub-connection-mqtt');

server.on('connection', function(connection) {
  mqttConnection = new Connection(connection);
  var bridge = new Bridge(mqttConnection, client);
});

This example shows how to connect a Client to a Bridge and then a Bridge to a broker (using another Client).

server.on('connection', function(connection) {
  var bridge = new Bridge(
    new MqttConnection(connection),
    new Client({port: MOSQUITTO_PORT}, Adapter)
  );

  bridge.connect();
});

Message broker

To distribute a message published to a topic, a client connects to a message broker. Client adapters allow pubsub clients to connect to various brokers. Clients can connect directly to brokers or indirectly using a bridge.

Adapter

Client adapters implement the Client API in a broker protocol-specific way.

Specify the adapter specific options using the name as the key.

{
  mqtt: {
    clientId: 'foobar'
  }
}

###Protocols

Strong-pubsub supports these two protocols:

It is possible to extend strong-pubsub to support other protocols, but that is beyond the scope of this README.

###Transports

Adapters / Clients require a tranpsort to create a connection and read / write data to / from.

A module (or object) that implements net.createConnection().

  • The standard TCP protocol: require('net')
  • Transport Layer Security (TLS), a secure cryptographic protocol: require('tls')
  • Primus (in development): require('strong-pubsub-transport-primus')

Transport swapping

This example shows how to switch betweenn different transports on the client.

//
// client side transport switching
//
var Adapter = require('strong-pubsub-mqtt');

// default
var TcpTransport = require('net'); // tcp (the default)
var client = new Client({host: 'localhost', port: 3000}, Adapter, TcpTransport);

// primus
var PrimusTransport = require('strong-pubsub-primus');
var client = new Client({host: 'localhost', port: 3000}, Adapter, PrimusTransport);

// tls
var TlsTransport = require('tls');
var client = new Client({host: 'localhost', port: 3000}, Adapter, TlsTransport);

//
// bridge transport swapping
//
var primusServer = PrimusTransport.createServer();
var tlsServer = TlsTransport.createServer();
var tcpServer = TcpTransport.createServer();

primusServer.on('connection', bridgeConnection);
tlsServer.on('connection', bridgeConnection);
tcpServer.on('connection', bridgeConnection);

function bridgeConnection(connection) {
  var bridge = new Bridge(
    new MqttConnection(connection),
    new Client({port: MOSQUITTO_PORT}, Adapter)
  );

  bridge.connect();
}

Connection

A Protocol connection implements a specific pubsub protocol in Node.js for use by strong-pubsub-bridge.

Architecture

This diagram illustrates how messages flow between clients, bridges, servers and brokers. The blue arrows represent a message published to a topic. The green arrow represents the message being sent to a subscriber.

Pubsub Architecture

Modules / Plugins

Examples

See the strong-pubsub-example repo.