Godsend Examples

node v4.9.1
version: 1.0.0
endpointsharetweet
var Class = require('godsend').Class; var Server = require('godsend').Server; var exchange = require('godsend').Exchange; var Bus = require('godsend').Bus; var Sequence = require('godsend').Sequence; Example = Class.extend({ initialize: function(properties) { new Server({ exchange : new exchange.Open() }).start(function() { new Agent().connect(function() { new Sender().connect(function() { console.log('Everything has started.'); }.bind(this)); }.bind(this)); }.bind(this)); } }); Agent = Class.extend({ connect: function(callback) { new Bus({ address: 'http://127.0.0.1:8080/' }).connect({ responded: function(result) { result.connection.process({ id: 'transform-object', on: function(request) { request.accept({ action: 'transform-object' }); }.bind(this), run: function(stream) { var object = stream.object; object.date = new Date(); stream.push(object); stream.next(); }.bind(this) }); callback(); }.bind(this) }); } }); Sender = Class.extend({ connect: function(callback) { new Bus({ address: 'http://127.0.0.1:8080' }).connect({ responded: function(result) { result.connection.send({ pattern: { action: 'transform-object' }, write: function(stream) { setInterval(function() { stream.write({ type: 'object' }); }.bind(this), 1000); }.bind(this), read: function(object) { console.log('Transformed object: ' + JSON.stringify(object, null, 2)); }, error: function(error) { console.log('error: ' + JSON.stringify(error, null, 2)); } }); callback(); }.bind(this) }); } }); new Example();
Loading…

no comments

    sign in to comment