-
Notifications
You must be signed in to change notification settings - Fork 0
/
consumer.js
43 lines (34 loc) · 1.03 KB
/
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
41
42
43
require("nodetime").profile();
var context = require('rabbit.js').createContext('amqp://ec2-46-137-6-37.eu-west-1.compute.amazonaws.com:5672');
var start;
var count = 0;
//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 - Creating context");
context.on('ready', function() {
console.log("Context Ready");
var sub = context.socket('SUB');
sub.connect('events', function() {
console.log("Connected to Events")
sub.setEncoding("utf-8");
sub.on("data", function(data){
var d = JSON.parse(data);
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++;
}
//console.log("Message", data)
})
});
});