- Simple
- Lightweight
- Promise based
- Easiest API as possible
- Designed with performance in mind
// server.js
var open = require('amqplib').connect('amqp://localhost')
var RpcServer = require('rmq-rpc').Server
var server = new RpcServer({
name: 'math',
methods: {
add ({ x, y }) {
console.log('add', x, y)
return Number(x) + Number(y)
},
sub ({ x, y }) {
console.log('sub', x, y)
return Number(x) - Number(y)
},
mul ({ x, y }) {
console.log('mul', x, y)
return Number(x) * Number(y)
},
div ({ x, y }) {
console.log('div', x, y)
return Number(x) / Number(y)
}
}
})
function main (channel) {
server.setup(channel)
}
open
.then(connection => connection.createChannel())
.then(main)
.catch(console.warn)
// client.js
var express = require('express')
var argv = require('minimist')(process.argv.slice(2))
var open = require('amqplib').connect('amqp://localhost')
var RpcClient = require('rmq-rpc').Client
var client = new RpcClient({ name: 'math' })
function main (channel) {
client.setup(channel)
}
open
.then(connection => connection.createChannel())
.then(main)
.catch(console.warn)
var app = express()
app.get('/add/:x/:y', function (req, res) {
client.call('add', req.params)
.then(result => res.send(String(result)))
})
app.get('/sub/:x/:y', function (req, res) {
client.call('sub', req.params)
.then(result => res.send(String(result)))
})
app.get('/mul/:x/:y', function (req, res) {
client.call('mul', req.params)
.then(result => res.send(String(result)))
})
app.get('/div/:x/:y', function (req, res) {
client.call('div', req.params)
.then(result => res.send(String(result)))
})
app.listen(argv.port, function () {
console.log(`Listening on port ${argv.port}`)
})
Command | Description |
---|---|
npm run check |
Check standard code style by snazzy |