-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
38 lines (30 loc) · 1.48 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
// server.js
const express = require('express');
const bodyParser = require('body-parser');
const CassandraBookRepository = require('./src/infrastructure/repositories/cassandraBookRepository');
const ElasticsearchBookRepository = require('./src/infrastructure/repositories/elasticsearchBookRepository');
const BookApplicationService = require('./src/application/services/bookApplicationService');
const BookController = require('./src/interfaces/rest/bookController');
const BookPublisher = require('./src/infrastructure/eventHandlers/bookPublisher');
const BookConsumer = require('./src/infrastructure/eventHandlers/bookConsumer');
const app = express();
app.use(bodyParser.json());
(async () => {
const cassandraRepo = new CassandraBookRepository();
const elasticRepo = new ElasticsearchBookRepository();
const bookPublisher = new BookPublisher();
await bookPublisher.connectRabbitMQ(); // Connect the publisher to RabbitMQ
const bookService = new BookApplicationService(cassandraRepo, elasticRepo, bookPublisher);
// Initialize and start consumer
const bookConsumer = new BookConsumer(bookService);
await bookConsumer.connectRabbitMQ();
bookConsumer.startRabbitMQConsumer();
// Initialize controllers
const bookController = new BookController(bookService);
// Routes
app.use(bookController.routes());
const PORT = process.env.PORT || 8082;
app.listen(PORT, () => {
console.log(`BookService running on port ${PORT}`);
});
})();