-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.js
47 lines (38 loc) · 1.31 KB
/
main.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
44
45
46
47
var send_to_sqs,
config = require('./config'),
Pusher = require('pusher-client'),
AWS = require('aws-sdk'),
SQS;
AWS.config.update({region: config.aws_region});
SQS = new AWS.SQS();
send_to_sqs = function (queue_name) {
return function (data) {
SQS.createQueue({QueueName: 'bitstamp_' + queue_name}, function (error, response) {
if (error) {
console.log(error);
return;
}
SQS.sendMessage({
QueueUrl: response.QueueUrl,
MessageBody: JSON.stringify(data)
}, function (error, response) {
if (error) {
console.log(error);
return;
}
});
});
};
};
for(var stream_i = 0; stream_i < config.streams.length; stream_i++) {
var stream = config.streams[stream_i],
pusher_client = new Pusher(stream.pusher_key);
for(var sub_i = 0; sub_i < stream.subscriptions.length; sub_i++) {
var subscription = stream.subscriptions[sub_i];
pusher_subscription = pusher_client.subscribe(subscription.channel);
pusher_subscription.bind(
subscription.event,
send_to_sqs([stream.stream_name, subscription.channel, subscription.event].join('_'))
);
}
}