From 4ff0adb64d26f4a3ca5dcbe1d8ed2cc04f69b9bd Mon Sep 17 00:00:00 2001 From: chanyeong Date: Fri, 30 Aug 2024 02:17:36 +0900 Subject: [PATCH] fix: debugging --- src/kafka/kafka.service.ts | 65 +++++++++++++++++++------------------- 1 file changed, 32 insertions(+), 33 deletions(-) diff --git a/src/kafka/kafka.service.ts b/src/kafka/kafka.service.ts index 34a2425..0df56fe 100644 --- a/src/kafka/kafka.service.ts +++ b/src/kafka/kafka.service.ts @@ -3,7 +3,6 @@ import { OnModuleInit, OnModuleDestroy, InternalServerErrorException, - OnApplicationBootstrap, } from '@nestjs/common'; import { Kafka, EachMessagePayload, Consumer } from 'kafkajs'; import { PuppeteerService } from '../puppeteer/puppeteer.service'; @@ -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'); }