2.0.1 • Published 9 years ago

rabbit-rpc v2.0.1

Weekly downloads
12
License
ISC
Repository
github
Last release
9 years ago

rabbit-rpc

simple rpc using RabbitMQ and amqp.node

Install

> npm install rabbit-rpc

example

caller.js

var rpc = require('rabbit-rpc')('amqp://localhost');

rpc.call('square', 99, function (err, res) {
    console.log('The square of 99 is', res);
});

handler.js

var rpc = require('rabbit-rpc')('amqp://localhost');

rpc.handle('square', function (num, callback) {
    callback(null, num*num);
});

Promises

rpc.promise('square', 99).then(function (res) {
    console.log('The square of 99 is', res);
});

Multiple arguments

rpc.call('sum', 1, 2, 3, function (err, res) {
    console.log('The sum is', res);
});

rpc.handle('sum', function (a, b, c, callback) {
    callback(null, a + b + c);
});

Multiple types

Send strings, numbers, arrays, objects or buffers. Arguments are serialized to BSON using node-buffalo.

rpc.call('getFile', __dirname, 'getfile.js', function (err, stats, data) {
    if (err) {
        return console.error('Got error', err);
    } else {
        console.log('Got file', stats.size, data.length);
    }
});

rpc.handle('getFile', function (dir, filename, callback) {
    var path = dir + '/' + filename;
    fs.stat(path, function (err, stats) {
        if (err) return callback(err);
        fs.readFile(path, function (err, data) {
            if (err) return callback(err);
            callback(null, stats, data)
        });
    });
});
2.0.1

9 years ago

2.0.0

9 years ago

1.1.6

9 years ago

1.1.5

9 years ago

1.1.4

9 years ago

1.1.3

9 years ago

1.1.2

9 years ago

1.1.1

9 years ago

1.1.0

9 years ago

1.0.1

9 years ago

1.0.0

9 years ago