amqplib wrapper for easier rabbitmq scripting of RPC interface
npm install @jackrabbit/rpc
The exported function takes the same parameters as amqplib.connect
,
and returns a object with two exported functions, client
and server
.
Sends data to queue and yields reply.
const { client } = require('@jackrabbit/rpc')(url)
client('rpc-queue', { message: true }, (err, result) => {
if (err) throw err
console.log(`worker returned ${result}`)
})
Consumes messages on given queue and passes them to worker. When worker calls done acknowledges the message and sends the result to the client.
const { server } = require('@jackrabbit/rpc')(url)
server('rpc-queue', (msg, done) => {
// do work
done(null, { result: true })
})
The test suite requires access to a rabbitMQ instance. You can run a dockerized container before running the tests:
./test/bin/rabbit
npm t