1.0.1 • Published 8 years ago

qpc v1.0.1

Weekly downloads
2
License
MIT
Repository
github
Last release
8 years ago

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

1.0.1

8 years ago

1.0.0

8 years ago

0.4.1

8 years ago

0.4.0

8 years ago

0.3.0

8 years ago

0.2.0

8 years ago

0.1.3

8 years ago

0.1.2

8 years ago

0.1.0

8 years ago