Search code examples
apache-kafkanestjskafkajs

NestJs/microservices Kafka - Consume messages per batch


I'm looking for consuming messages per batch with nestjs/microservices by using the decorator @MessagePattern('topic') or something equivalent. I would like to fetch multiple records together, process them and then, send the commit of the latest record when all the batch has been processed. I used before batch listeners in Spring Kafka to do this.

Should I use kafkajs or is there a way with nestjs/microservices ?


Solution

  • I think nestJs is using kafkaJs under the hood, which does batching even if you're processing with eachMessage. However if you need more direct control over the batch you'd use https://kafka.js.org/docs/consuming#a-name-each-batch-a-eachbatch.