Skip to content
jacobgroundwater edited this page Feb 3, 2013 · 2 revisions

Install

$ npm install federation

Usage

Basic Messaging

// Boilerplate
var fed = require('federation');
var dir = fed.init().director;

// Create Some Actors
var bob = dir.createActor('bob');
var tom = dir.createActor('tom');

// Assign Behaviours
bob.onMessage = function(msg){
  console.log('Bob Got Message: %s',msg);
}
tom.onMessage = function(msg){
  console.log('Tom Got Message: %s',msg);
}

// Start Messaging!
bob.tell('tom','hi');
tom.tell('bob','bye');

Request-Reply Messaging

// Boilerplate
var fed = require('federation');
var dir = fed.init().director;

// Create Some Actors
var bob = dir.createActor('bob');
var tom = dir.createActor('tom');

// Assign Behaviours
bob.onMessage = function(msg,reply){
  reply('My name is Bob.');
}

// Ask Away
tom.ask('bob','what is your name?',function(err,reply){
  if(err) return console.error('Error asking Bob:',err);
  console.log('Got Reply:',reply);
});
Clone this wiki locally