| 1 | import { NestFactory } from '@nestjs/core'; |
| 2 | import { NotificationsServiceModule } from './notifications-service.module'; |
| 3 | import { MicroserviceOptions, Transport } from '@nestjs/microservices'; |
| 4 | import { KAFKA_BROKER, KAFKA_CLIENT_ID } from '@app/kafka'; |
| 5 | import { SERVICES_PORTS } from '@app/common'; |
| 6 | |
| 7 | async function bootstrap() { |
| 8 | const app = await NestFactory.create(NotificationsServiceModule); |
| 9 | |
| 10 | // connect kafka microservices for consuming events |
| 11 | app.connectMicroservice<MicroserviceOptions>({ |
| 12 | transport: Transport.KAFKA, |
| 13 | options: { |
| 14 | client: { |
| 15 | clientId: `${KAFKA_CLIENT_ID}-notifications`, |
| 16 | brokers: [KAFKA_BROKER], |
| 17 | }, |
| 18 | consumer: { |
| 19 | groupId: `notifications-consumer-group`, |
| 20 | }, |
| 21 | }, |
| 22 | }); |
| 23 | |
| 24 | // start microservices (kafka consumer) |
| 25 | await app.startAllMicroservices(); |
| 26 | |
| 27 | await app.listen(SERVICES_PORTS.NOTIFICATIONS_SERVICE); |
| 28 | console.log( |
| 29 | `Notifications Service is running on port ${SERVICES_PORTS.NOTIFICATIONS_SERVICE}`, |
| 30 | ); |
| 31 | console.log('KAfka consumer started'); |
| 32 | } |
| 33 | bootstrap(); |