Skip to content
This repository has been archived by the owner on Apr 23, 2024. It is now read-only.

mariosant/work

Repository files navigation

Work

Guaranteed to do the work!

ko-fi

NPM version CircleCI

Work is a framework for developing processing systems that rely on RabbitMQ. It provides the developer a simplified set of tools to build

Installation

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.

Usage

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

Development

Easy-peasy!

$ yarn install        # to install dependencies
$ yarn test           # to run the test suite
$ docker-compose up   # run a local Rabbit MQ instance

Meta

Marios Antonoudiou – @marios_ant[email protected]

Distributed under the MIT license.

https://github.com/mariosant/work

Contributing

  1. Fork it (https://github.com/mariosant/work/fork)
  2. Create your feature branch (git checkout -b feature/fooBar)
  3. Commit your changes using a semantic commit message.
  4. Push to the branch (git push origin feature/fooBar)
  5. Create a new Pull Request

About

Guaranteed to do the work

Resources

Stars

Watchers

Forks

Sponsor this project

Packages

No packages published