uva-amqp
v0.7.1
Published
AMQP RPC driver for Node.js using the uva interface.
Downloads
9
Readme
uva-amqp
The uva RPC interface implementation for AMQP.
Installation
npm install --save uva-amqp
Usage
Create a microservice for mathematical calculations and implement some remote methods.
const uva = require('uva-amqp')
uva.server({
channel: 'mathOperations',
amqpURL: 'amqp://guest:guest@localhost:5672',
})
.then(server => {
server.addMethods({
sum(a, b, cb) {
cb(null, a + b)
},
factorial(n, cb) {
let f = 1
for (let i = 2; i <= n; i++) {
f *= i
}
cb(null, f)
},
})
server.start()
})
Create a client for the math microservice and call some of its remote methods.
const uva = require('uva-amqp')
uva.client({
channel: 'mathOperations',
amqpURL: 'amqp://guest:guest@localhost:5672',
})
.then(math => {
math.sum(12, 2, function(err, sum) {
console.log(sum)
})
/* if the last argument is not a callback, the function will return a promise */
math.factorial(10).then(function(result) {
console.log(result)
}, function(err) {
console.error(err)
})
})
License
The MIT License (MIT)