-
Notifications
You must be signed in to change notification settings - Fork 5
Forward routing
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.
- a fully functional example
- the minimum code required to create a forward-router.
- the forward-routers routes file
- the routes file for processes connecting to the forward-router
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.
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.
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.