autohost-pubsub

0.1.0 • Public • Published

autohost-pubsub

A backbone that allows clients to manage subscriptions to system-wide events.

The intention is that clients can manage what topics they subscribe to via the web socket API or HTTP API.

Web Socket API

// subscribes to a specific topic
socket.emit( "subscription.add", { topic: "my.topic" } );
 
// subscribes to any topic beginning with `my`
socket.emit( "subscription.add", { topic: "my.#" } );
 
// unsubscribes to a topic
socket.emit( "subscription.remove", { topic: "my.topic" } );

HTTP API

This example demonstrates using a halon client to make the calls. (because hypermedia makes everything better)

var client = halon({
    root: "http://yourserver/api",
    adapter: halon.jQueryAdapter($)
});
 
client.subscription.add( { topic: "my.topic" } );
 
client.subscription.remove( { topic: "my.topic" } );

Installation & Setup

npm install autohost-pubsub -S
var autohost = require( "autohost" );
var host;
var hyped = require( "hyped" )();
var fount = require( "fount" );
var postal = require( "postal" );
// create the channel used to communicate between
// a message backbone/app and the pubsub resource
var channel = postal.channel( "ahpubsub" );
 
fount.register( "ahpubsub", channel );
host = hyped.createHost( autohost, {
    port: config.nonstop.host.port,
    modules: [
        "autohost-pubsub"
    ],
    fount: fount
}, function() {
    host.start();
} );
 
// you can plug any message/event backbone into this system using the postal channel
// just publish events to the topics as the clients have subscribed to them
// and it will handle the rest ...
 
// this example demonstrates how you could forward messages from a rabbit
// queue via wascally and use the routing key of the message as the topic
rabbit.on( "some.important.message", function( message ) {
    channel.publish( message.fields.routingKey, message.body );
} );

Package Sidebar

Install

npm i autohost-pubsub

Weekly Downloads

1

Version

0.1.0

License

MIT

Last publish

Collaborators

  • arobson