Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/titarenko/mqu
Job and event distribution built on top of RabbitMQ.
https://github.com/titarenko/mqu
Last synced: about 1 month ago
JSON representation
Job and event distribution built on top of RabbitMQ.
- Host: GitHub
- URL: https://github.com/titarenko/mqu
- Owner: titarenko
- Created: 2017-08-25T09:36:43.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2023-11-03T11:35:14.000Z (about 1 year ago)
- Last Synced: 2024-11-06T05:45:32.508Z (2 months ago)
- Language: JavaScript
- Size: 125 KB
- Stars: 2
- Watchers: 3
- Forks: 2
- Open Issues: 9
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# mqu
```bash
npm i mqu
```## Example
```js
const mqu = require('mqu')('amqp://guest:guest@localhost:5672')mqu.on('error', error => {
console.error('oh my, error!!', error)
process.kill(process.pid)
})mqu.on('connect', () => {
console.error('connect method succeeded')
})mqu.consumeJob('j', data => console.log('worker 1', data))
mqu.consumeJob('j', data => console.log('worker 2', data))mqu.consumeEvent('e', data => console.log('\thandler 1', data))
mqu.consumeEvent('e', data => console.log('\thandler 2', data))
mqu.consumeEvent('e', data => console.log('\thandler 3', data))const jobInterval = setInterval(() => {
const job = new Date().toISOString() + '-job'
mqu.publishJob('j', job).then(() => console.log('published job', job))
}, 2000)const eventInterval = setInterval(() => {
const ev = new Date().toISOString() + '-event'
mqu.publishEvent('e', ev).then(() => console.log('published event', ev))
}, 1500)process.on('SIGINT', () => {
clearInterval(jobInterval)
clearInterval(eventInterval)
mqu.close().then(() => console.log('closed!'))
})
```## Events
- `error` - emitted when transport, protocol or consumer error is occurred
- `connect` - emitted when a protocol level connection is ready## Why?
Because best [RabbitMQ](https://www.rabbitmq.com/) client for [node.js](https://nodejs.org) [bramqp](https://github.com/bakkerthehacker/bramqp) is too verbose to be used directly for:
- round robin distribution of jobs between workers
- fanout distribution of events to listeners## License
MIT