Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 25 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,9 @@ Run multiple servers.js for round-robin shared.
###server.js example

var rpc = require('amqp-rpc').factory({
url: "amqp://guest:guest@localhost:5672"
});
exchange: "uuu-test", exchange_options: {exclusive: false, autoDelete: true},
conn_options: {url: "amqp://guest:guest@rabbitmq:5672", heartbeat: 10}
});


rpc.on('inc', function(param, cb){
Expand Down Expand Up @@ -58,8 +59,9 @@ Run multiple servers.js for round-robin shared.
###client.js example

var rpc = require('amqp-rpc').factory({
url: "amqp://guest:guest@localhost:5672"
});
exchange: "uuu-test", exchange_options: {exclusive: false, autoDelete: true},
conn_options: {url: "amqp://guest:guest@rabbitmq:5672", heartbeat: 10}
});

rpc.call('inc', 5, function() {
console.log('results of inc:', arguments); //output: [6,4,7]
Expand Down Expand Up @@ -144,3 +146,22 @@ Results for three workers:
host2:2822 uptime= 2279.16 seconds counter= 3

Eugene Demchenko aka Goldy skype demchenkoe email [email protected]



## Changelog

0.2.4:

* bugfix memory leak

0.2.3:

* support for other exchanges than rpc_exchange


0.2.2:

* print channels fn


2 changes: 1 addition & 1 deletion example/broadcast/core.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
var rpc = require('../../index').factory({
url: "amqp://guest:guest@localhost:5672"
url: "amqp://tdev1:[email protected]:5672"
});

var all_stats = {};
Expand Down
13 changes: 7 additions & 6 deletions example/broadcast/worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@ var worker_name = os.hostname() + ':' + process.pid;
var counter = 0;

var rpc = require('../../index').factory({
url: "amqp://guest:guest@localhost:5672"
url: "amqp://tdev1:[email protected]:5672"
});

rpc.onBroadcast('getWorkerStat', function(params, cb) {
if(params && params.type == 'fullStat') {
rpc.on('getWorkerStat', function (params, cb) {
console.log("getWorkerStat: " + worker_name);
if (params && params.type == 'fullStat') {
cb(null, {
pid: process.pid,
hostname: os.hostname(),
Expand All @@ -16,9 +17,9 @@ rpc.onBroadcast('getWorkerStat', function(params, cb) {
});
}
else {
cb(null, { counter: counter++ })
cb(null, {counter: counter++})
}
});
}, {queueName: "test-" + process.pid});


rpc.call('log', { worker: worker_name, message: 'worker started' });
rpc.rpcCall('log', {worker: worker_name, message: 'worker started'});
31 changes: 26 additions & 5 deletions example/round-robin/client.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,39 @@
Object.defineProperty(Error, 'fromJSON', {
value: function (other) {
var err = new Error();
Object.getOwnPropertyNames(other).forEach(function (key) {
err[key] = other[key];
});
return err;
},
configurable: true
});

var rpc = require('../../index').factory({
conn_options: { url: "amqp://guest:guest@localhost:5672", heartbeat: 10 }
exchange: "uuu-test", exchange_options: {exclusive: false, autoDelete: true},
conn_options: {url: "amqp://guest:guest@rabbitmq:5672", heartbeat: 10, confirm: true}
});

rpc.call('inc', 5, function() {
rpc.rpcCall('inc', 5, null, null, function () {
console.log('results of inc:', arguments); //output: [6,4,7]
});

rpc.call('say.Hello', { name: 'John' }, function(msg) {
rpc.rpcCall('say.Hello', {name: 'John'}, null, null, function (msg) {
console.log('results of say.Hello:', msg); //output: Hello John!
});

rpc.call('withoutCB', {}, function(msg) {
rpc.rpcCall('withoutCB', {}, null, null, function (msg) {
console.log('withoutCB results:', msg); //output: please run function without cb parameter
});

rpc.call('withoutCB', {}); //output message on server side console
//rpc.rpcCall('withoutCB', {}); //output message on server side console

//rpc.rpcCall('errorFn', null, null, null, function (err, succ) {
// throw Error.fromJSON(err);
//});

//rpc.rpcCall('waitsTooMuch', null, null, console, console.log);
//rpc.rpcCall('waitsTooMuch', null, null, console, console.log);

rpc.rpcCall('waitsTooMuch', null, {"expiration": "3000"}, console, console.log);
rpc.rpcCall('waitsTooMuch', null, {"expiration": "3000"}, console, console.log);
49 changes: 36 additions & 13 deletions example/round-robin/server.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,30 @@
Object.defineProperty(Error.prototype, 'toJSON', {
value: function () {
var alt = {};

Object.getOwnPropertyNames(this).forEach(function (key) {
alt[key] = this[key];
}, this);

return alt;
},
configurable: true
});


var rpc = require('../../index').factory({
conn_options: { url: "amqp://guest:guest@localhost:5672", heartbeat: 10 }
exchange: "uuu-test", exchange_options: {exclusive: false, autoDelete: true},
conn_options: {url: "amqp://guest:guest@rabbitmq:5672", heartbeat: 10}
});


rpc.on('inc', function(param, cb){
rpc.subscribe('zzttrr', function(param, cb){
var prevVal = param;
var nextVal = param+2;
var nextVal = param + 2;
cb(++param, prevVal, nextVal);
});

rpc.on('say.*', function(param, cb, inf){
}, {queueName: "test_inc"});

rpc.subscribe('say.*', function (param, cb, inf) {
var arr = inf.cmd.split('.');

var name = (param && param.name) ? param.name : 'world';
Expand All @@ -20,13 +33,23 @@ rpc.on('say.*', function(param, cb, inf){

});

rpc.on('withoutCB', function(param, cb, inf) {
rpc.subscribe('withoutCB', function (param, cb, inf) {

if (cb) {
cb('please run function without cb parameter')
}
else {
console.log('this is function withoutCB');
}

if(cb){
cb('please run function without cb parameter')
}
else{
console.log('this is function withoutCB');
}
});

rpc.subscribe('errorFn', function (param, cb) {
cb(new Error("errorFn"), null);
});

rpc.subscribe('waitsTooMuch', function (param, cb) {
console.log("waitsTooMuch");
//cb("waitsTooMuch OK!");
setTimeout(cb.bind(null, "waitsTooMuch OK!"), 5000);
});
Loading