clusterfuck
v1.3.0
Published
wip cluster management
Readme
clusterfuck
WIP cluster management.
Write your code once and use configuration to route your services together. You should be able to define whether cluster('foo') requires a local module or returns a http request to http://foo/ without touching code.
Every service is a Stream, so it works either required locally or over the network.
Example
var clusterfuck = require('clusterfuck');
var cluster = clusterfuck({
'@mic/site-header': 'http://localhost:8000'
});
var header = cluster('@mic/site-header');
// over http
header().pipe(process.stdout);
var layout = cluster('@mic/site-layout');
// require()d locally
layout().pipe(process.stdout);You can for example use minimist to inject service location through stdarg:
var minimist = require('minimist');
var clusterfuck = require('clusterfuck');
var cluster = clusterfuck(minimist(process.argv.slice(2)));
var header = cluster('@mic/site-header');
// over http
header().pipe(process.stdout);
var layout = cluster('@mic/site-layout');
// require()d locally
layout().pipe(process.stdout);and launch via:
$ node server.js --@mic/site-header=http://localhost:8000Adapters
If no mapping is provided for a service, it will simply be require()d.
HTTP
var cluster = clusterfuck({
'@mic/site-header': 'http://header.mic.com'
});
var header = cluster('@mic/site-header');
header('section', { some: 'opts' }).pipe(process.stdout)will result in this request to get a header stream:
GET http://header.mic.com/section?some=optsNested properties are supported via qs.
Caching
var cluster = clusterfuck({
'@mic/site-header': {
source: 'http://header.mic.com',
cache: true
}
});
var header = cluster('@mic/site-header');
header('a').pipe(process.stdout); // fill the cache
// ...
header('a').pipe(process.stdout); // use the cache
// ...
header('b').pipe(process.stdout); // new args -> new cacheInstallation
$ npm install clusterfuckAPI
var cluster = clusterfuck(map)
Create a cluster with given map from service names to remote locations.
cluster.events
EventEmitter, see Events.
var service = cluster(name)
Create a constructor for the service known as name.
service([args, ][opts])
Create a readable stream from service with optional string args and an array of opts.
Events
The following events will be emitted for every outgoing request (read: not a require()), and will have the following properties:
requestidtransporturl
responseidtransporturlstatus
There is a simple debug logger included, set the environment variable CLUSTERLOG=true to enable it.
Example:
cluster.events.on('response', function(res){
if (res.transport == 'http') console.log('GET %s %s', res.url, res.status);
});License
MIT
