@jackrabbit/pubsub
v0.3.1
Published
amqplib wrapper for easier rabbitmq scripting of pub/sub model
Downloads
6
Maintainers
Readme
@jackrabbit/pubsub
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.