Gusto
v0.0.2
Published
micro services library
Downloads
1
Readme
Gusto
Micro service library
Gusto is a simple micro service library.
Needs node version > 5.00 to work.
TODO. Add more message transport layers.
Add a better pattern matching transport that supports nested objects.
Documentation, more examples...
listen to all messages
'use strict'
const _gusto = require('gusto');
const gusto = new _gusto();
gusto.connect('global_message_bus', () => {
gusto.tap('*', (err, message) => {
// listen to all messages
console.log(message);
});
});
listen for a paticular micro service
'use strict'
const _gusto = require('gusto');
const gusto = new _gusto();
gusto.connect('global_message_bus', () => {
gusto.tap('{ math: "*" }', (err, message) => {
// listen to all messages from the math micro service.
console.log(message);
});
});
// the math microservice would emit messages like this:
gusto.emit({
math: {
result: some_operation(...operands)
}
});
another example
'use strict'
const _gusto = require('gusto');
const gusto = new _gusto();
gusto.connect('global_message_bus', () => {
gusto.tap('{ demo: "*" }', (err, message) => {
if(err) console.log(err);
let parse = message.demo.cmd;
let _parse = parse.split(':');
let left_op = _parse[1].split('_')[0];
let right_op = _parse[1].split('_')[1];
let result = parseInt(left_op) + parseInt(right_op);
gusto.emit({
math: {
result: result,
timestamp: new Date().toISOString()
}
});
});
});
setInterval(()=>{
let left_op = Math.floor(Math.random()*11)+5;
let right_op = Math.floor(Math.random()*11)+5;
let command = `add:${left_op}_${right_op}`;
gusto.emit({
demo: {
cmd: command,
timestamp: new Date().toISOString()
}
});
}, 5000);
gusto.tap('*', (err, message) => {
console.log('[monitor] ', message);
/*
[example output]
[monitor] { demo: { cmd: 'add:9_5' } }
[monitor] { math: { result: 14 } }
[monitor] { demo: { cmd: 'add:6_11' } }
[monitor] { math: { result: 17 } }
*/
})
setTimeout(() => {
console.log('Thanks for trying Gusto!');
process.exit(0);
}, 45000);