RPC library based on AMQP protocol.
Example: Call remote function.
Run multiple servers.js for round-robin shared.
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')
})
})
const qpc = require('qpc')
qpc.publisher({
uri: 'amqp://guest:guest@localhost:5672',
})
.then(publisher => {
publisher.call('inc', 5, () => {
console.log('results of inc:', arguments)
})
publisher.call('say.Hello', { name: 'John' }, msg => {
console.log('results of say.Hello:', msg)
})
publisher.call('withoutCB', {}, msg => {
console.log('withoutCB results:', msg)
})
publisher.call('withoutCB', {})
})