amqplib wrapper for easier rabbitmq scripting of pub/sub model
npm install @jackrabbit/pubsub
The exported function takes the same parameters as amqplib.connect
,
and returns a object with two exported functions, publish
and subscribe
.
Sends data to subscribers and yields.
const { publish } = require('@jackrabbit/pubsub')(url)
publish('tasks', { message: true }, (err) => {
if (err) throw err
// message delivered
})
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 })
})
Contributions welcome! Please read the contributing guidelines first.