Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/davesag/amqp-delegate
A simple, but performant, remote worker system that uses AMQP to coordinate jobs.
https://github.com/davesag/amqp-delegate
agent amqp delegator remote-worker worker
Last synced: about 2 months ago
JSON representation
A simple, but performant, remote worker system that uses AMQP to coordinate jobs.
- Host: GitHub
- URL: https://github.com/davesag/amqp-delegate
- Owner: davesag
- License: mit
- Created: 2019-01-27T07:23:12.000Z (almost 6 years ago)
- Default Branch: develop
- Last Pushed: 2024-04-29T07:33:24.000Z (9 months ago)
- Last Synced: 2024-05-02T00:12:06.492Z (9 months ago)
- Topics: agent, amqp, delegator, remote-worker, worker
- Language: JavaScript
- Homepage:
- Size: 2.9 MB
- Stars: 23
- Watchers: 4
- Forks: 2
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- Funding: .github/FUNDING.yml
- License: LICENSE
- Security: SECURITY.md
Awesome Lists containing this project
README
# amqp-delegate
A remote worker system that uses `AMQP` to coordinate jobs.
[![NPM](https://nodei.co/npm/amqp-delegate.png)](https://nodei.co/npm/amqp-delegate/)
## See Also
- [`amqp-simple-pub-sub`](https://github.com/davesag/amqp-simple-pub-sub) — A library that simplifies use of `AMQP` based publishers and subscribers.
## Usage
```sh
npm install amqp-delegate
```## Worker
```js
const { makeWorker } = require('amqp-delegate')const worker = makeWorker({
url: 'ampq://localhost:5672', // the default
name: 'the name of the worker', // required
task: async () => 'any pure async function', // required
onError: err => { // optional
console.error('A connection error happened', err) // or do something clever
}
onClose: () => { // optional
console.log('The connection has closed.') // or do something clever
}
})// start it
worker.start().then(() => {
console.log('worker', worker.name, 'started')
})// stop it
worker.stop().then(() => {
console.log('worker', worker.name, 'stopped')
})
```## Delegator
```js
const { makeDelegator } = require('amqp-delegate')const delegator = makeWorker({
url: 'ampq://localhost:5672', // the default
onError: err => { // optional
console.error('A connection error happened', err) // or something clever
}
onClose: () => { // optional
console.log('The connection has closed.') // or something clever
}
})delegator
.start()
.then(() => {
delegator.invoke('worker name', ...params)
console.log('job name', result)
})
.catch(err => {
console.error('worker name', err)
})
```## A concrete example
### The worker
```js
const { makeWorker } = require('amqp-delegate')const task = (a, b) => new Promise(resolve => setTimeout(() => resolve(a + b), 10))
const worker = makeWorker({
name: 'adder',
task
})worker
.start()
.then(() => {
process.on('SIGINT', () => {
worker.stop().then(() => {
process.exit(0)
})
})
})
.catch(err => {
console.error('caught', err)
})
```### The delegator
```js
const { makeDelegator } = require('amqp-delegate')const delegator = makeDelegator()
delegator
.start()
.then(() => delegator.invoke('adder', 10, 15))
.then(result => {
console.log('result', result)
})
.catch(err => {
console.error('caught', err)
})
```## Development
### Branches
| branch | status | coverage | Audit | notes |
| ------ | ------ | -------- | ----- | ----- |
| `develop` | [![CircleCI](https://circleci.com/gh/davesag/amqp-delegate/tree/develop.svg?style=svg)](https://circleci.com/gh/davesag/amqp-delegate/tree/develop) | [![codecov](https://codecov.io/gh/davesag/amqp-delegate/branch/develop/graph/badge.svg)](https://codecov.io/gh/davesag/amqp-delegate) | [![Vulnerabilities](https://snyk.io/test/github/davesag/amqp-delegate/develop/badge.svg)](https://snyk.io/test/github/davesag/amqp-delegate/develop) | Work in progress |
| `main` | [![CircleCI](https://circleci.com/gh/davesag/amqp-delegate/tree/main.svg?style=svg)](https://circleci.com/gh/davesag/amqp-delegate/tree/main) | [![codecov](https://codecov.io/gh/davesag/amqp-delegate/branch/main/graph/badge.svg)](https://codecov.io/gh/davesag/amqp-delegate) | [![Vulnerabilities](https://snyk.io/test/github/davesag/amqp-delegate/main/badge.svg)](https://snyk.io/test/github/davesag/amqp-delegate/main) | Latest stable release |### Prerequisites
- [NodeJS](htps://nodejs.org), 10.0+ (I use [`nvm`](https://github.com/creationix/nvm) to manage Node versions — `brew install nvm`.)
- [Docker](https://www.docker.com) (Use [Docker for Mac](https://docs.docker.com/docker-for-mac/), not the homebrew version)### Initialisation
```sh
npm install
```### To Start the queue server for integration testing
```sh
docker-compose up -d
```Runs Rabbit MQ.
### Test it
- `npm test` — runs the unit tests (does not need `rabbitmq`)
- `npm run test:unit:cov` — runs the unit tests with code coverage (does not need `rabbitmq`)
- `npm run test:integration` — runs the integration tests (needs `rabbitmq`)### Lint it
```sh
npm run lint
```## Contributing
Please see the [contributing notes](CONTRIBUTING.md).