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

Unfortunately routing is an overloaded term in federation. We use the term forward routing to mean any situation where a packet is relayed through an intermediate process. That is, a host that is neither the source or destination of the packet. Forward routing lets you create complex topologies.

Forward Routing Diagram

QuickStart Example

Allow Forwarding

Any instance of federation can act as a forward-router, but this functionality is switched off by default. This helps prevent accidental topological loops.

Whenever the director object receives a message, it attempts to deliver the message to a local actor first. This behaviour cannot be changed. If however there is no local actor satisfying the packets named destination, the director will check to see if it can be forwarded. Every packet contains a counter that increments each time it is forwarded. The packet will only be forwarded if the counter is below the maximum allowed forwards.

By default the maximum allowed forwards is 0. Change this by setting the max_forwards property.

var fed = require('federation');
var dir = fed.init().director;
dir.max_forwards = 1;

Setting max_forwards to 1 allows a single hop, good enough for a star topology.

Configure Routes

Once a packet has been forwarded, it is routed as if it originated from the current process. As such, it will consult the current processes routing table.

In a start topology, only the center process need have a comprehensive routing table.

Updating the Routes Table Programatically

The routes table is available from

var director = require('federation').init();
console.log(director.router.table);

You can replace the table, and the change will be immediate.