@jackrabbit/pubsub

0.3.1 • Public • Published

@jackrabbit/pubsub

npm travis standard license

amqplib wrapper for easier rabbitmq scripting of pub/sub model

Install

npm install @jackrabbit/pubsub

Usage

pubsub(url, [options])

The exported function takes the same parameters as amqplib.connect, and returns a object with two exported functions, publish and subscribe.

publish(exchange, message, done)

Sends data to subscribers and yields.

const { publish } = require('@jackrabbit/pubsub')(url)

publish('tasks', { message: true }, (err) => {
  if (err) throw err

  // message delivered
})

subscribe(exchange, worker)

Consumes messages on subscribed topics and passes them to worker. When worker calls done acknowledges the message and sends the result to the client.

const { subscribe } = require('@jackrabbit/pubsub')(url)

subscribe('tasks', (msg, done) => {
  // do work

  done(null, { result: true })
})

Contribute

Contributions welcome! Please read the contributing guidelines first.

License

MIT

Package Sidebar

Install

npm i @jackrabbit/pubsub

Weekly Downloads

1

Version

0.3.1

License

MIT

Last publish

Collaborators

  • jackboberg