Skip to content

Commit

Permalink
fix: debugging
Browse files Browse the repository at this point in the history
  • Loading branch information
jcy0308 committed Aug 29, 2024
1 parent fd07beb commit 4ff0adb
Showing 1 changed file with 32 additions and 33 deletions.
65 changes: 32 additions & 33 deletions src/kafka/kafka.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import {
OnModuleInit,
OnModuleDestroy,
InternalServerErrorException,
OnApplicationBootstrap,
} from '@nestjs/common';
import { Kafka, EachMessagePayload, Consumer } from 'kafkajs';
import { PuppeteerService } from '../puppeteer/puppeteer.service';
Expand Down Expand Up @@ -43,38 +42,38 @@ export class KafkaService implements OnModuleInit, OnModuleDestroy {
console.log('connected');
await this.consumer.subscribe({ topic: this.topic, fromBeginning: false });
console.log('subsribed');
await this.consumer
.run({
autoCommit: false,
eachMessage: async (payload: EachMessagePayload) => {
const { topic, partition, message } = payload;
console.info(
`partition: ${partition}, messageOffset: ${message.offset}`,
);
const uuid = message.key.toString();
const htmlContent = message.value.toString();
try {
const pdf = await this.puppeteerService.generatePDF(htmlContent);
await this.minioService.uploadPdf(
uuid,
Buffer.from(pdf),
message.headers,
);
// 성공 시 커밋
// throw new BadGatewayException('일부러 에러 발생');
await this.consumer.commitOffsets([
{
topic,
partition,
offset: (BigInt(message.offset) + BigInt(1)).toString(),
},
]);
} catch (e) {
throw new InternalServerErrorException(`[consumer] ${e.message}`);
}
},
})
.catch((e) => console.error(`[example/consumer] ${e.message}`, e));
// await this.consumer
// .run({
// autoCommit: false,
// eachMessage: async (payload: EachMessagePayload) => {
// const { topic, partition, message } = payload;
// console.info(
// `partition: ${partition}, messageOffset: ${message.offset}`,
// );
// const uuid = message.key.toString();
// const htmlContent = message.value.toString();
// try {
// const pdf = await this.puppeteerService.generatePDF(htmlContent);
// await this.minioService.uploadPdf(
// uuid,
// Buffer.from(pdf),
// message.headers,
// );
// // 성공 시 커밋
// // throw new BadGatewayException('일부러 에러 발생');
// await this.consumer.commitOffsets([
// {
// topic,
// partition,
// offset: (BigInt(message.offset) + BigInt(1)).toString(),
// },
// ]);
// } catch (e) {
// throw new InternalServerErrorException(`[consumer] ${e.message}`);
// }
// },
// })
// .catch((e) => console.error(`[example/consumer] ${e.message}`, e));
console.log('consumer has started');
}

Expand Down

0 comments on commit 4ff0adb

Please sign in to comment.