-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathqueue_processor.js
More file actions
65 lines (48 loc) · 1.75 KB
/
queue_processor.js
File metadata and controls
65 lines (48 loc) · 1.75 KB
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
/* jshint shadow:true */
/* jshint sub:true */
var config = require('./config');
var queueProcessor = function() {
"use strict";
var io = require('socket.io-client');
var Stomp = require('stomp-client');
var socket;
var mq_client;
var counter = 0;
function stop() {
if (mq_client) {
mq_client.disconnect(function() {
console.log("Disconnected from MQ");
});
}
if (socket) {
socket.emit('disconnect');
}
setTimeout(process.exit, 500);
}
return {
start: function() {
mq_client = new Stomp(config.mq.mqHost, config.mq.mqPort, config.mq.mqLogin, config.mq.mqPasscode);
mq_client.connect(
function(sessionId) {
console.log("Connected to MQ: ", sessionId);
socket = new io.connect(config.mq.wsServerURL);
socket.on('stop', function(){
stop();
});
mq_client.subscribe(config.mq.mqName, function(body, headers) {
var reading_js = JSON.parse(body);
socket.emit('reading', { reading : reading_js});
// counter++;
// console.log(counter, body );
});
},
function(err) {
console.log("MQ " + err);
console.log("Retry in 60 seconds");
setTimeout(queueProcessor.start, 60000);
}
);
}
};
}();
queueProcessor.start();