bozz
v1.1.3
Published
Here is your new microservices' boss(zz) !
Downloads
30
Readme
Bozz
Here is your new microservices' boss(zz) !
It allows you to build a coherent ecosystem based on two main principles :
- Key based requests
- Pattern based events
Requests
Concept : Someone requests something, another one reacts and send a response.
Requests example
A file index.js
:
const ms = require(`bozz`).createMs();
ms.onRequest(`users.getOne`, ({ id }) => ({
id,
firstname : `John`,
lastname : `Doe`,
}));
ms.init()
.then(() => ms.request(`users.getOne`, { id : 123 }))
.then(console.log);
And in console when running node index.js
:
{ id: 123, firstname: 'John', lastname: 'Doe' }
To simple ? Ok, let's try to split code in two differents services :
service1.js
:
const ms = require(`bozz`).createMs();
ms.onRequest(`users.getOne`, ({ id }) => ({
id,
firstname : `John`,
lastname : `Doe`,
}));
ms.init();
service2.js
:
const ms = require(`bozz`).createMs();
ms.init()
.then(() => ms.request(`users.getOne`, { id : 123 }))
.then(console.log);
Run in one console node service1.js
and in another node service2.js
, look at the service2's console :
{ id: 123, firstname: 'John', lastname: 'Doe' }
Events
Concept : Someone broadcasts an event and 0 to x others reacts but no one can answer.
Events example
service1.js
:
const ms = require(`bozz`).createMs();
ms.onEvent(`user:created`, console.log);
ms.onEvent(`user:*`, console.log);
ms.init();
service2.js
:
const ms = require(`bozz`).createMs();
ms.onEvent(`user:created`, console.log);
ms.init()
.then(() => ms.broadcast(`user:created`, { id : 123 }));
Run in one console node service1.js
and in another node service2.js
.
Look at the service1's console :
user:created { id : 123 }
user:created { id : 123 }
Look at the service2's console :
user:created { id : 123 }
Available plugins
bozz-load-dir : Automatically load a directory of bozz files