Skip to content

jackboberg/rabbit-rpc

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

57 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

@jackrabbit/rpc

npm travis standard license

amqplib wrapper for easier rabbitmq scripting of RPC interface

Install

npm install @jackrabbit/rpc

Usage

rpc(url, [options])

The exported function takes the same parameters as amqplib.connect, and returns a object with two exported functions, client and server.

client(queueName, data, done)

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}`)
})

server(queueName, worker, [capacity])

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 })
})

Development

The test suite requires access to a rabbitMQ instance. You can run a dockerized container before running the tests:

./test/bin/rabbit
npm t

About

amqplib wrapper for easier rabbitmq scripting of RPC interface

Resources

License

Stars

Watchers

Forks

Packages

No packages published