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
socket.emit( "subscription.add", { topic: "my.topic" } );
socket.emit( "subscription.add", { topic: "my.#" } );
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" );
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();
} );
rabbit.on( "some.important.message", function( message ) {
channel.publish( message.fields.routingKey, message.body );
} );