https://github.com/yamalight/microwork
Microwork - simple creation of distributed scalable microservices in node.js with RabbitMQ
https://github.com/yamalight/microwork
job-queue microservices nodejs rabbitmq
Last synced: 9 months ago
JSON representation
Microwork - simple creation of distributed scalable microservices in node.js with RabbitMQ
- Host: GitHub
- URL: https://github.com/yamalight/microwork
- Owner: yamalight
- Created: 2016-02-02T14:48:41.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2018-10-01T16:07:28.000Z (over 7 years ago)
- Last Synced: 2025-01-14T14:27:48.828Z (over 1 year ago)
- Topics: job-queue, microservices, nodejs, rabbitmq
- Language: JavaScript
- Homepage:
- Size: 304 KB
- Stars: 97
- Watchers: 5
- Forks: 9
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
Awesome Lists containing this project
README
# Microwork.js
[](https://www.npmjs.com/package/microwork)
[](http://opensource.org/licenses/MIT)
[](https://travis-ci.org/yamalight/microwork)
[](https://coveralls.io/github/yamalight/microwork?branch=master)
Microwork.js is a library for simple creation of distributed scalable microservices in node.js with RabbitMQ.
# Installation
```sh
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](docs/Plugins.md)
# 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):
```js
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:
```js
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](docs/README.md).
## License
[MIT](http://www.opensource.org/licenses/mit-license)