-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexample.js
81 lines (71 loc) · 2.44 KB
/
example.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
// Abusix Raw Threat Intellience
// Exmaple Node.js script
// npm install stompit
const stompit = require('stompit');
const util = require('util');
// Put your credentials here
const config = {
"user": "<YOUR USERNAME>",
"pass": "<YOUR PASSWORD>",
"topic": "<TOPIC>",
// If you want a shared subscription make this value
// the same for each process that should share the data.
// "channel": ${config.user} + "-" + "myprocess",
}
var start_stomp_client = function () {
stompit.connect({
"host": "streams.abusix.net",
"port": 61612,
"ssl": true,
"maxLineLength": 1048576,
"connectHeaders": {
"login": config.user,
"passcode": config.pass,
"heart-beat": "30000,30000",
}
}, (err, client) => {
var self = this;
function retry() {
if (client) client.disconnect();
console.log('STOMP: attempting to reconnect');
setTimeout(() => {
self.start_stomp_client(config);
}, 5 * 1000);
}
if (err) {
console.log(`STOMP: connect error (${err.message})`);
return retry();
}
client.on('error', (cerr) => {
console.error(`STOMP: client error (${cerr.message})`);
return retry();
});
console.log(`STOMP: connected`);
var topics = config.topic;
if (!Array.isArray(topics)) {
topics = topics.replace(/\s+/g,'').split(/[;,]/);
}
topics.forEach((topic) => {
console.log(`STOMP: subscribing to topic: ${topic} (channel: ${config.channel})`);
client.subscribe({
"channel": config.channel || null,
"destination": `/topic/${topic}`,
"ack": "auto"
}, (serr, message) => {
if (serr) {
console.error(`STOMP: ${topic} subscribe error (${serr.message})`);
return;
}
message.readString('utf-8', (merr, body) => {
if (merr) {
console.error(`STOMP: ${topic} message read error (${merr.message})`);
return;
}
// Your code to handle the input messages
console.log(util.inspect(body));
});
});
});
});
}
start_stomp_client();