Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/efraespada/cluster-eventbus
Simple library for communicating different Node processes. Works with clusters.
https://github.com/efraespada/cluster-eventbus
Last synced: 5 days ago
JSON representation
Simple library for communicating different Node processes. Works with clusters.
- Host: GitHub
- URL: https://github.com/efraespada/cluster-eventbus
- Owner: efraespada
- License: apache-2.0
- Created: 2019-04-28T00:32:26.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2020-04-16T02:02:10.000Z (over 4 years ago)
- Last Synced: 2024-10-14T09:31:59.937Z (about 1 month ago)
- Language: JavaScript
- Homepage:
- Size: 175 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Cluster EventBus
[![npm version][npm-badge]][npm]
[![Build Status][travis-badge]][travis]
[![Dependency Status][david-badge]][david]
[![DevDependency Status][david-badge-dev]][david-dev]Simple library for communicating different processes.
I developed the library for communicating different cluster processes. It also connects different machines in the same local network to share clusters and distribute the work.
```bash
$ npm install cluster-eventbus --save
```Sample working on a Node cluster:
```js
const numCPUs = require('os').cpus().length;
const cluster = require('cluster');
const EventBus = require('cluster-eventbus');let eventBus = new EventBus({
core: `MacBook Pro (914)`,
debug: true
}).cluster(cluster);if (cluster.isMaster) {
for (let i = 1; i < numCPUs + 1; i++) {
cluster.fork();
}
} else {
eventBus.prepareWorker(cluster, (params) => {
// do something with params
// and return something
return {
"message": `hello ${params.id}, I'm worker_${cluster.worker.id}`,
"params_received": params
};
}
);
}
```
### Ask
Ask something to a worker:
```js
let response = await eventBus.event(`MacBook Pro (914)`,`worker_1`, {
"message": `hello worker 1`,
"id": `test_worker`
})
```
Response model:
```json
{
"response": {},
"error": true,
"error_message": ""
}
```
### Ask To All
Ask the same to all workers:
```js
let response = await eventBus.eventAll({
"message": `hello workers`,
"id": `test_worker`,
"data": {
"method": "get_name"
}
})
```
Response model:
```json
{
"responses": [{}, {}],
"error": true,
"error_messages": ["", ""]
}
```### Close Process
Close everything by calling:
```bash
await eventBus.closeAll();
```### Machine Name
```js
EventBus.MACHINE_NAME
```
Response:
```
MacBook Pro (914)
```[david]: https://david-dm.org/efraespada/cluster-eventbus
[david-badge]: https://david-dm.org/efraespada/cluster-eventbus.svg
[travis]: https://travis-ci.org/efraespada/cluster-eventbus
[travis-badge]: https://travis-ci.org/efraespada/cluster-eventbus.svg?branch=master
[david-dev]: https://david-dm.org/efraespada/cluster-eventbus?type=dev
[david-badge-dev]: https://david-dm.org/efraespada/cluster-eventbus/dev-status.svg
[npm]: https://www.npmjs.com/package/cluster-eventbus
[npm-badge]: https://badge.fury.io/js/cluster-eventbus.svg