qpc

1.0.1 • Public • Published

qpc

RPC library based on AMQP protocol.

Dependency Status Build Status npm version Coverage Status

Install RabbitMQ

apt-get install rabbitmq-server

Install library

npm install qpc

round-robin

Example: Call remote function. Run multiple servers.js for round-robin shared.

server.js example

const qpc = require('qpc')
 
qpc.consumer({
  uri: 'amqp://guest:guest@localhost:5672',
})
.then(consumer => {
  consumer.on('inc', (param, cb) => cb(++param, param, param + 2))
 
  consumer.on('say.*', (param, cb, inf) => {
    const arr = inf.cmd.split('.')
 
    const name = (param && param.name) ? param.name : 'world'
 
    cb(arr[1] + ' ' + name + '!')
  })
 
  consumer.on('withoutCB', (param, cb, inf) => {
    if (cb) {
      cb('please run function without cb parameter')
      return
    }
 
    console.log('this is function withoutCB')
  })
})

client.js example

const qpc = require('qpc')
 
qpc.publisher({
  uri: 'amqp://guest:guest@localhost:5672',
})
.then(publisher => {
  publisher.call('inc', 5, () => {
    console.log('results of inc:', arguments)  //output: [6,4,7]
  })
 
  publisher.call('say.Hello', { name: 'John' }, msg => {
    console.log('results of say.Hello:', msg)  //output: Hello John!
  })
 
  publisher.call('withoutCB', {}, msg => {
    console.log('withoutCB results:', msg)
    //output: please run function without cb parameter
  })
 
  publisher.call('withoutCB', {}) //output message on server side console
})

License

MIT © Zoltan Kochan

Readme

Keywords

Package Sidebar

Install

npm i qpc

Weekly Downloads

2

Version

1.0.1

License

MIT

Last publish

Collaborators

  • zkochan