-
Notifications
You must be signed in to change notification settings - Fork 0
/
websockets.ts
70 lines (55 loc) · 2.25 KB
/
websockets.ts
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
// import express, { Request, Response, Application, NextFunction } from "express";
// // sockets
// import * as http from 'http';
// import * as WebSocket from 'ws';
// const app = express()
// // sockets
// const server = http.createServer(app);
// const wss = new WebSocket.Server({server, path: "/api/socket/buckets"})
// // msg queue
// const amqp = require("amqplib/callback_api")
// // when connection established
// wss.on('connection', (ws: WebSocket) => {
// //function executed when websocket on server receives a message
// ws.on('message', (subdomain: string) => {
// subdomain = subdomain.toString()
// //log the received message
// console.log('bucket subdomain: %s', subdomain);
// // creating a channel with amqp msg q
// amqp.connect("amqp://diego:password@localhost/RabbitsInParis", function(error0: any, connection: any) {
// if (error0) {
// console.log(error0)
// throw error0;
// }
// connection.createChannel(function(error1: any, channel: any) {
// if (error1) {
// throw error1
// }
// // create a queueu that will consume from the newly created queue
// channel.assertQueue(subdomain, {
// durable: false,
// exclusive: false
// }, function(error2: any, q: any) {
// if (error2) {
// throw error2;
// }
// channel.prefetch(100);
// channel.consume(q.queue, function(msg: any) {
// if(msg.content) {
// ws.send(msg.content.toString())
// }
// }, {
// noAck: true
// });
// });
// })
// //immediately after subscribe to the created qmsg broker /
// })
// });
// ws.on("close", () => {
// console.log("ws connection closed")
// })
// // initial connection acknowledgement on client and server side
// console.log("websocket connection established")
// });
// server.listen(3001, () => console.log('Web Socket erver listening on port '+ 3001));