Giter Site home page Giter Site logo

mqu's Introduction

mqu

npm i mqu

Example

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 client for node.js bramqp is too verbose to be used directly for:

  • round robin distribution of jobs between workers
  • fanout distribution of events to listeners

License

MIT

mqu's People

Contributors

titarenko avatar akhll avatar lafayette avatar maxnowack avatar

Stargazers

BlueSharkPartners avatar Egor Gumenyuk avatar

Watchers

James Cloos avatar  avatar  avatar

Forkers

koriwi lafayette

mqu's Issues

.publishJob error doesn't get caught in catch block

Code sample to reproduce

// I intentionally changed port 5672 -> 5673 to get an error
const mqu = require('mqu')('amqp://guest:guest@localhost:5673')

async function main () {
	try {
		await mqu.publishJob('job', { kappa: 'lul' })
	} catch (error) {
		// Doesn't catch
		console.error('Caught', error)
	}
}

main()

// Doesn't catch
process.on('unhandledRejection', (error) => console.error('Unhandled', error))
// Caught here :thinking_face:
process.on('uncaughtException', (error) => console.error('Uncaught', error))

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.