Microwork - simple creation of distributed scalable microservices in node.js with RabbitMQ
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
docs
src Update eslintrc to use prettier, reformat code with prettier Sep 14, 2017
test Update dependencies and fix test/build toolchain Oct 1, 2018
.eslintrc Update eslintrc to use prettier, reformat code with prettier Sep 14, 2017
.gitignore document code, remove unnecessary addWorker method Feb 3, 2016
.travis.yml Setup autodeploy to npm from travis on tags Sep 14, 2017
CHANGELOG.md Release 0.12.1 Sep 14, 2017
README.md Update dependencies and fix test/build toolchain Oct 1, 2018
package-lock.json Update dependencies and fix test/build toolchain Oct 1, 2018
package.json Release 0.12.2 Oct 1, 2018
yarn.lock Update dependencies Sep 14, 2017

README.md

Microwork.js

npm MIT Build Status Coverage Status

Microwork.js is a library for simple creation of distributed scalable microservices in node.js with RabbitMQ.

Installation

npm install --save microwork

Requirements

Since Microwork.js is written in ES6 and it uses async/await - it requires latest stable node (7.x or later).

Features

  • Simple interface for building distributed (micro)services
  • Easy way to scale services both horizontally (by adding more nodes) and vertically (by adding more subscribers)
  • Extensible with plugins

Usage

Quick start

Example service that subscribe to messages from do.work topic and does some work with incoming data (in this case it just appends world! to incoming string):

const Microwork = require('microwork');

// create task runner
const runner = new Microwork({host: 'your.rabbit.host', exchange: 'your.exchange'});
// add worker to specific topic
await runner.subscribe('do.work', (msg, reply) => {
  reply('response.topic', msg + ' world!');
});
// after work is done - cleanup
await runner.stop();

Example service that subscribes to messages from response.topic and logs them to console, as well as sends processing request to previously defined service:

const Microwork = require('microwork');

// create master
const master = new Microwork({host: 'your.rabbit.host', exchange: 'your.exchange'});
// listen for reply from workers
await master.subscribe('response.topic', msg => {
  console.log(msg); // -> "hello world!"
});
// send message to workers
await master.send('do.work', 'hello');

// after work is done - cleanup
await master.stop();

For more examples see project documentation.

License

MIT