-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
41 lines (37 loc) · 1.23 KB
/
app.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
process.env.NODE_TLS_REJECT_UNAUTHORIZED = "0";
const stompit = require('stompit');
const settings = require("./settings");
const host = settings.host;
const QUEUE = settings.queue;
const TOPIC = settings.topic;
let client = null;
stompit.connect({ host: host, port: 61613 }, (err, _client) => {
if(err) {
console.error("err: ", err);
}else {
client = _client;
let timer = null;
client.subscribe({ destination: QUEUE }, (err, msg) => {
msg.readString('UTF-8', (err, body) => {
console.log("queue: ", body);
});
});
client.subscribe({ destination: TOPIC }, (err, msg) => {
msg.readString('UTF-8', (err, body) => {
console.log("topic1: ", body);
});
});
setTimeout(()=>{
const event1 = client.send({ destination: QUEUE });
event1.write(JSON.stringify({RequestKey: 'queue'}));
event1.end();
const event2 = client.send({ destination: TOPIC });
event2.write(JSON.stringify({RequestKey: 'topic1'}));
event2.end();
}, 1000);
}
});
process.on("SIGINT", ()=>{
console.log("exit");
client && client.disconnect();
});