Skip to content

Commit

Permalink
fix: fromBeginning true
Browse files Browse the repository at this point in the history
  • Loading branch information
jcy0308 committed Aug 30, 2024
1 parent 3b0b1ed commit 9373413
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 22 deletions.
37 changes: 16 additions & 21 deletions src/kafka/kafka.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export class KafkaService implements OnModuleInit, OnModuleDestroy {
async onModuleInit() {
await this.consumer.connect();
console.log('connected');
await this.consumer.subscribe({ topic: this.topic, fromBeginning: false });
await this.consumer.subscribe({ topic: this.topic, fromBeginning: true });
console.log('subsribed');
await this.consumer
.run({
Expand All @@ -46,27 +46,22 @@ export class KafkaService implements OnModuleInit, OnModuleDestroy {
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}`);
}
const pdf = await this.puppeteerService.generatePDF(htmlContent);
await this.minioService.uploadPdf(
message.headers.uuid,
Buffer.from(pdf),
message.headers,
);
// 성공 시 커밋
// throw new BadGatewayException('일부러 에러 발생');
await this.consumer.commitOffsets([
{
topic,
partition,
offset: (BigInt(message.offset) + BigInt(1)).toString(),
},
]);
},
})
.catch((e) => console.error(`[example/consumer] ${e.message}`, e));
Expand Down
2 changes: 1 addition & 1 deletion src/minio/minio-client.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export class MinioClientService {
this.bucketName = this.configService.get('MINIO_BUCKET_NAME');
}

async uploadPdf(fileName: string, pdfBuffer: Buffer, headers): Promise<void> {
async uploadPdf(fileName, pdfBuffer: Buffer, headers): Promise<void> {
const metaData = {
'Content-Type': 'application/pdf',
createdAt: new Date().toUTCString(),
Expand Down

0 comments on commit 9373413

Please sign in to comment.