-
Notifications
You must be signed in to change notification settings - Fork 27
/
package.json
40 lines (40 loc) · 4.83 KB
/
package.json
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
{
"name": "amqp-rpc",
"description": "AMQP RPC driver for node.js",
"keywords": [
"amqp",
"rpc"
],
"version": "0.0.8",
"preferGlobal": true,
"author": {
"name": "Eugene Demchenko"
},
"repository": {
"type": "git",
"url": "git://github.com/demchenkoe/node-amqp-rpc.git"
},
"bugs": {
"url": "http://github.com/demchenkoe/node-amqp-rpc/issues"
},
"main": "./index",
"engines": {
"node": ">=0.4"
},
"licenses": [
{
"type": "MIT",
"url": "http://raw.github.com/demchenkoe/node-amqp-rpc/master/LICENSE"
}
],
"dependencies": {
"amqp": "0.2.0",
"node-uuid": "*",
"debug": "~0.7.2"
},
"readme": "\n#AMQP-RPC\n\nRPC library based on AMQP protocol.\nTested with RabbitMQ on the highload project.\n\n\n###Install RabitMQ\n\n apt-get install rabbitmq-server\n\n###Install library\n\n npm install amqp-rpc\n\n##round-robin\n\nExample: Call remote function.\nRun multiple servers.js for round-robin shared.\n\n\n###server.js example\n\n var rpc = require('amqp-rpc').factory({\n url: \"amqp://guest:guest@localhost:5672\"\n });\n\n\n rpc.on('inc', function(param, cb){\n var prevVal = param;\n var nextVal = param+2;\n cb(++param, prevVal, nextVal);\n });\n\n rpc.on('say.*', function(param, cb, inf){\n\n var arr = inf.cmd.split('.');\n\n var name = (param && param.name) ? param.name : 'world';\n\n cb(arr[1] + ' ' + name + '!');\n\n });\n\n rpc.on('withoutCB', function(param, cb, inf) {\n\n if(cb){\n cb('please run function without cb parameter')\n }\n else{\n console.log('this is function withoutCB');\n }\n\n });\n\n\n\n###client.js example\n\n var rpc = require('amqp-rpc').factory({\n url: \"amqp://guest:guest@localhost:5672\"\n });\n\n rpc.call('inc', 5, function() {\n console.log('results of inc:', arguments); //output: [6,4,7]\n });\n\n rpc.call('say.Hello', { name: 'John' }, function(msg) {\n console.log('results of say.Hello:', msg); //output: Hello John!\n });\n\n rpc.call('withoutCB', {}, function(msg) {\n console.log('withoutCB results:', msg); //output: please run function without cb parameter\n });\n\n rpc.call('withoutCB', {}); //output message on server side console\n\n\n##broadcast\n\nExample: Core receiving data from all workers.\nRun multiple worker.js for broadcast witness.\nThe core.js must be launched after all worker.js instances.\n\n###example/broadcast/worker.js\n\n var os = require('os');\n var worker_name = os.hostname() + ':' + process.pid;\n var counter = 0;\n\n var rpc = require('../../index').factory({\n url: \"amqp://guest:guest@localhost:5672\"\n });\n\n rpc.onBroadcast('getWorkerStat', function(params, cb) {\n if(params && params.type == 'fullStat') {\n cb(null, {\n pid: process.pid,\n hostname: os.hostname(),\n uptime: process.uptime(),\n counter: counter++\n });\n }\n else {\n cb(null, { counter: counter++ })\n }\n });\n\n###example/broadcast/core.js\n\n var rpc = require('../../index').factory({\n url: \"amqp://guest:guest@localhost:5672\"\n });\n\n var all_stats = {};\n\n //rpc.callBroadcast() is rpc.call() + waiting multiple responses\n //If remote handler without response data, you can use rpc.call() for initiate broadcast calls.\n\n rpc.callBroadcast(\n 'getWorkerStat',\n { type: 'fullStat'}, //request parameters\n { //call options\n ttl: 1000, //wait response time (1 seconds), after run onComplete\n onResponse: function(err, stat) { //callback on each worker response\n all_stats[ stat.hostname+':'+ stat.pid ] = stat;\n\n },\n onComplete: function() { //callback on ttl expired\n console.log('----------------------- WORKER STATISTICS ----------------------------------------');\n for(var worker in all_stats) {\n s = all_stats[worker];\n console.log(worker, '\\tuptime=', s.uptime.toFixed(2) + ' seconds', '\\tcounter=', s.counter);\n }\n }\n });\n\n\nResults for three workers:\n\n ----------------------- WORKER STATISTICS ----------------------------------------\n host1:2612 \tuptime= 2470.39 seconds \tcounter= 2\n host2:1615 \tuptime= 3723.53 seconds \tcounter= 8\n host2:2822 \tuptime= 2279.16 seconds \tcounter= 3\n\nEugene Demchenko aka Goldy skype demchenkoe email demchenkoev@gmail.com\n",
"readmeFilename": "README.md",
"homepage": "https://github.com/demchenkoe/node-amqp-rpc",
"_id": "amqp-rpc@0.0.5",
"_from": "amqp-rpc@0.0.5"
}