-
Notifications
You must be signed in to change notification settings - Fork 3
/
server.js
43 lines (37 loc) · 1.22 KB
/
server.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
import { app } from './app';
import { getTrendingLocationsJob, getTrendsJob, getGlobalTrendsJob } from './cronGetTrends';
import { logger } from './service/LoggerService';
import {
consumeTrendsFromKafka,
consumeTrendsTweetsFromKafka
} from './service/KafkaConsumerService';
import WebSocket from 'ws';
const port = process.env.PORT || 3000;
const server = app.listen(port, '0.0.0.0', function() {
logger.info('Server running on port: ' + port);
});
try {
logger.info('Starting kafka consumer');
consumeTrendsFromKafka();
} catch (error) {
logger.error('Failed to start consumeTrendsFromKafka from kafka' + error);
}
try {
logger.info('Starting TrendsTweetsFromKafka consumer');
consumeTrendsTweetsFromKafka();
} catch (error) {
logger.error('Failed to start consumeTrendsTweetsFromKafka from kafka' + error);
}
try {
getTrendingLocationsJob.start();
getTrendsJob.start();
getGlobalTrendsJob.start();
} catch (error) {
logger.error('Failed to start cron job. Error: ' + error);
}
const wss = new WebSocket.Server({ port: 34234 });
wss.on('connection', function(ws) {
ws.send('Connected to server');
logger.info('connected to client: ' + JSON.stringify(ws._socket.address()));
});
module.exports.wsserver = wss;