Switch branches/tags
Nothing to show
Find file
Fetching contributors…
Cannot retrieve contributors at this time
66 lines (46 sloc) 1.63 KB

Node.js service broker and provisioner

Simple scalable example setup

  • one or more provisioning servers (examples/provisioner.js)
  • one or more service proxies per provisioning server (examples/proxy.js)
  • multiple clients (examples/trigger.js)
  • a pubsub-capable messagebus (redis implementation included)

Typical client workflow

  1. client picks a random channel name.
var commchannel = 'mycomm/' + uuid.v1();
  1. client tells the provisioner that it expects a specific service running on that channel.
bus.publish('provisioner', { 
	type: 'provision',
	service: 'randomnumberservice',
	channel: commchannel
  1. provisioner then tells one of all available proxies to start that service up on that channel.

  2. client talks directly to service on selected channel.

bus.subscribe(commchannel, function (chan, msg) {
	console.log('message from service:', msg);

bus.publish(commchannel, {
	action: 'something',

Writing services is also simple

This is a sample service reporting random values back at given intervals to the client, and listens for an killsignal which stops it.

var commchannel = process.argv[2]; // channel name is first argument 
console.log('## Sample service - communicating on channel '+commchannel);

bus.subscribe(commchannel, function (chan, msg) {
	if (msg.type == 'stop-service')
setInterval(function () { 
	bus.publish( commchannel, { type:'data', value:Math.random()*1000 } );
}, 2000);