Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

amqp-delegate

Package Overview
Dependencies
Maintainers
1
Versions
16
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

amqp-delegate

A very simplistic, but performant, remote worker system that uses AMQP to coordinate jobs.

  • 1.0.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
6
increased by500%
Maintainers
1
Weekly downloads
 
Created
Source

amqp-delegate

A very simplistic, but performant, remote worker system that uses AMQP to coordinate jobs.

Greenkeeper badge

branchstatuscoveragenotes
developCircleCIcodecovWork in progress
masterCircleCIcodecovLatest stable release

Worker

const { makeWorker } = require('amqp-delegate')

const worker = makeWorker({
  url: <the url of the amqp server> - defaults to ampq://localhost,
  name: <the name of the worker> — required,
  task: <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

const { makeDelegator } = require('amqp-delegate')

const delegator = makeWorker({
  exchange: <the name of the exchange to use> — defaults to '',
  url: <the url of the amqp server> - defaults to ampq://localhost,
  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
  }
})

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

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

const delegator = makeDelegator()

delegator
  .start()
  .then(() => delegator.invoke('adder', 10, 15))
  .then(result => {
    console.log('result', result)
  })
  .catch(err => {
    console.error('caught', err)
  })

TODO

  • documentation
  • publish to npm

Development

Prerequisites

Initialisation

npm install

To Start the queue server for integration testing.

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)

note Node 11.7+ breaks nyc and mocha — see https://github.com/nodejs/node/issues/25650

Lint it

npm run lint

Contributing

Please see the contributing notes.

Keywords

FAQs

Package last updated on 28 Jan 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc