@modulus/rabbit-pubsub
v0.2.1
Published
amqplib wrapper for easier rabbitmq scripting of pub/sub model
Downloads
9
Readme
Rabbit-PubSub
amqplib wrapper for easier rabbitmq scripting of pub/sub model
Install
npm install @modulus/rabbit-pubsub
Usage
RabbitPubSub(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 PubSub = require('@modulus/rabbit-rpc')(url)
PubSub.publish('tasks', { message: true }, (err, result) => {
if (err) throw err // unable to publish
console.log('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 PubSub = require('@modulus/rabbit-rpc')(url)
PubSub.subscribe('tasks', (msg, done) => {
// do work
done(null, { result: true })
})
Contribute
Contributions welcome! Please read the contributing guidelines first.