Skip to content

jackboberg/rabbit-pubsub

Repository files navigation

@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

About

amqplib wrapper for easier rabbitmq scripting of pub/sub model

Resources

License

Stars

Watchers

Forks

Packages

No packages published