-
Notifications
You must be signed in to change notification settings - Fork 0
/
consumer.js
40 lines (34 loc) · 1000 Bytes
/
consumer.js
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
require("nodetime").profile();
var zmq = require('zmq')
, sock = zmq.socket('pull');
var start;
var count = 0;
var host = 'tcp://' + (!!process.argv[2] ? process.argv[2] : "127.0.0.1")
var port = ":" + (!!process.argv[3] ? process.argv[3] : "3000");
//Workaround to avoid Heroku resetting the app for not binding to the designated port
if(process.env.PORT) {
console.log("heroku workaround");
net = require("net");
net.createServer().listen(process.env.PORT);
}
console.log('Consumer connected to ' + (host + port));
sock.connect(host + port);
sock.on('message', function(msg){
try{
var d = JSON.parse(msg);
if(!start) {
start = new Date();
console.log("Start Receiving", start.getTime());
}
if(d.end) {
var end = (new Date()).getTime();
console.log("End Receiving: " + end + " ms", "Time: " + (end - start) + " ms" ,"Count:" + count);
process.exit(0);
} else {
count++;
}
} catch(e){
console.log("Error: ", e);
}
//console.log("Message", data)
});