-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
48 lines (40 loc) · 1.19 KB
/
index.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
var redisUrl = process.env.MESSAGE_BUS_REDIS_URL || "127.0.0.1";
var redis = require("redis"),
redisClient = redis.createClient(6379, redisUrl);
var AWS = require('aws-sdk');
AWS.config.region = 'us-east-1';
var kinesis = new AWS.Kinesis();
redisClient.on("ready", function () {
console.log("Connected to Redis!");
redisClient.psubscribe("*");
});
redisClient.on("pmessage", function (pattern, channel, message) {
var c = channel.split(":");
var model = c[0];
var action = c[1];
// console.log("Model: ", model);
// console.log("Action: ", action);
// console.log("Message: ", message);
var msg = JSON.parse(message);
var data = {
channel: channel,
model: model,
action: action,
message: msg
}
var params = {
Data: JSON.stringify(data), /* required */
PartitionKey: channel, /* required */
StreamName: 'mantle', /* required */
};
kinesis.putRecord(params, function(err, data) {
if (err) {
console.log('Error on channel: ' + channel);
console.log(err, err.stack);
}
// else console.log(data); // successful response
});
});
redisClient.on("error", function (err) {
console.log("Redis error: " + err);
});