Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9dcc4b3
commit 9e297e1
Showing
7 changed files
with
203 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
var rpc = require('../../index').factory({ | ||
url: "amqp://guest:guest@localhost:5672" | ||
}); | ||
|
||
var all_stats = {}; | ||
|
||
//rpc.callBroadcast() is rpc.call() + waiting multiple responses | ||
//If remote handler without response data, you can use rpc.call() for initiate broadcast calls. | ||
|
||
rpc.callBroadcast( | ||
'getWorkerStat', | ||
{ type: 'fullStat'}, //request parameters | ||
{ //call options | ||
ttl: 1000, //wait response time (1 seconds), after run onComplete | ||
onResponse: function(err, stat) { //callback on each worker response | ||
all_stats[ stat.hostname+':'+ stat.pid ] = stat; | ||
|
||
}, | ||
onComplete: function() { //callback on ttl expired | ||
console.log('----------------------- WORKER STATISTICS ----------------------------------------'); | ||
for(var worker in all_stats) { | ||
s = all_stats[worker]; | ||
console.log(worker, '\tuptime=', s.uptime.toFixed(2) + ' seconds', '\tcounter=', s.counter); | ||
} | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
var os = require('os'); | ||
var worker_name = os.hostname() + ':' + process.pid; | ||
var counter = 0; | ||
|
||
var rpc = require('../../index').factory({ | ||
url: "amqp://guest:guest@localhost:5672" | ||
}); | ||
|
||
rpc.onBroadcast('getWorkerStat', function(params, cb) { | ||
if(params && params.type == 'fullStat') { | ||
cb(null, { | ||
pid: process.pid, | ||
hostname: os.hostname(), | ||
uptime: process.uptime(), | ||
counter: counter++ | ||
}); | ||
} | ||
else { | ||
cb(null, { counter: counter++ }) | ||
} | ||
}); | ||
|
||
|
||
rpc.call('log', { worker: worker_name, message: 'worker started' }); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters