Skip to content

Commit

Permalink
fix: add logging
Browse files Browse the repository at this point in the history
  • Loading branch information
jcy0308 committed Aug 29, 2024
1 parent 077ffad commit fd07beb
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
7 changes: 4 additions & 3 deletions src/kafka/kafka.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { PuppeteerService } from '../puppeteer/puppeteer.service';
import { MinioService } from '../minio/minio.service';

@Injectable()
export class KafkaService implements OnApplicationBootstrap, OnModuleDestroy {
export class KafkaService implements OnModuleInit, OnModuleDestroy {
private kafka: Kafka;
private consumer: Consumer;
private topic = process.env.TOPIC;
Expand All @@ -27,7 +27,6 @@ export class KafkaService implements OnApplicationBootstrap, OnModuleDestroy {
'kafka-controller-2.kafka-controller-headless.kafka.svc.cluster.local:9092',
],
sasl: {
// mechanism: `process.env.SASL_MECHANISM`,
mechanism: 'scram-sha-256',
username: process.env.SASL_USER,
password: process.env.SASL_PASSWORD,
Expand All @@ -39,9 +38,11 @@ export class KafkaService implements OnApplicationBootstrap, OnModuleDestroy {
});
}

async onApplicationBootstrap() {
async onModuleInit() {
await this.consumer.connect();
console.log('connected');
await this.consumer.subscribe({ topic: this.topic, fromBeginning: false });
console.log('subsribed');
await this.consumer
.run({
autoCommit: false,
Expand Down
2 changes: 1 addition & 1 deletion src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ import { AppModule } from './app.module';
async function bootstrap() {
const app = await NestFactory.create(AppModule);
app.enableShutdownHooks();
await app.listen(5000);
await app.listen(4000);
}
bootstrap();

0 comments on commit fd07beb

Please sign in to comment.