Guaranteed to do the work!
Work is a framework for developing processing systems that rely on RabbitMQ. It provides the developer a simplified set of tools to build
Add @mariosant/work
to your package.json
.
$ npm install @mariosant/work
For local development, you might want run an instance of Rabbit MQ, via docker.
The idea is pretty simple. Develop modules that consume messages and run them via a cli tool or programmatically.
// consumer.js
const {getContent} = require('@mariosant/work')
const consume = (message. {publish, retry, reject}, context) => {
const content = getContent(message);
// Process the message here. No need to return anything.
// Async/await is fully supported.
// If you need to retry processing, call retry()
// If you need to discard the message, call reject()
// And if you need to publish a new message, call publish(topic, content)
};
const init = ({publish}) => {
// anything you return here, it is going to be available in the consume's context
}
// Export the following
module.exports = {
consume,
init,
uri: 'amqp://guest:guest@localhost',
exchange: 'test-exchange',
queue: 'service-name',
routingKey: 'records.#',
};
And run it:
$ npx work consumer.js
Easy-peasy!
$ yarn install # to install dependencies
$ yarn test # to run the test suite
$ docker-compose up # run a local Rabbit MQ instance
Marios Antonoudiou – @marios_ant – [email protected]
Distributed under the MIT license.
https://github.com/mariosant/work
- Fork it (https://github.com/mariosant/work/fork)
- Create your feature branch (
git checkout -b feature/fooBar
) - Commit your changes using a semantic commit message.
- Push to the branch (
git push origin feature/fooBar
) - Create a new Pull Request