1.1.3 • Published 4 years ago

bozz v1.1.3

Weekly downloads
247
License
MIT
Repository
github
Last release
4 years ago

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

1.1.3

4 years ago

1.1.2

6 years ago

1.1.1

6 years ago

1.1.0

6 years ago

1.0.6

6 years ago

1.0.5

6 years ago

1.0.4

6 years ago

1.0.3

6 years ago

1.0.2

6 years ago

1.0.1

6 years ago

1.0.0

6 years ago

0.1.0

6 years ago

0.0.95

6 years ago

0.0.92

6 years ago

0.0.91

6 years ago

0.0.9

7 years ago

0.0.8

7 years ago

0.0.6

7 years ago

0.0.5

7 years ago

0.0.4

7 years ago

0.0.3

7 years ago

0.0.2

7 years ago

0.0.1

7 years ago