Home Reference Source Repository

Microwork.js

npm MIT Build Status bitHound Overall Score Coverage Status Code docs

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, it uses babel to compile the code before publishing. Currently we're using es2015-node babel preset that only works in latest stable node (4.x or later).

Features

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):

import Microwork from '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:

import Microwork from '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