Skip to content

Commit

Permalink
Update ConsumerExample.md
Browse files Browse the repository at this point in the history
ConsumerSubscribeTopic is deprecated and has been replaced with ConsumerSubscribeTopics.
eachBatchPayload was spelled wrong as eatchBatchPayload.
eachBatchPayload does not directly have {topic, partition} as properties. These properties can be directly be found on the {batch} property rather.
  • Loading branch information
stilyng94 committed Jun 30, 2022
1 parent 62526d0 commit b7bb7db
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions docs/ConsumerExample.md
Expand Up @@ -69,7 +69,7 @@ signalTraps.forEach(type => {
A similar example in TypeScript

```typescript
import { Consumer, ConsumerSubscribeTopic, EachBatchPayload, Kafka, EachMessagePayload } from 'kafkajs'
import { Consumer, ConsumerSubscribeTopics, EachBatchPayload, Kafka, EachMessagePayload } from 'kafkajs'

export default class ExampleConsumer {
private kafkaConsumer: Consumer
Expand All @@ -81,8 +81,8 @@ export default class ExampleConsumer {
}

public async startConsumer(): Promise<void> {
const topic: ConsumerSubscribeTopic = {
topic: 'example-topic',
const topic: ConsumerSubscribeTopics = {
topics: ['example-topic'],
fromBeginning: false
}

Expand All @@ -103,19 +103,19 @@ export default class ExampleConsumer {
}

public async startBatchConsumer(): Promise<void> {
const topic: ConsumerSubscribeTopic = {
topic: 'example-topic',
const topic: ConsumerSubscribeTopics = {
topics: ['example-topic'],
fromBeginning: false
}

try {
await this.kafkaConsumer.connect()
await this.kafkaConsumer.subscribe(topic)
await this.kafkaConsumer.run({
eachBatch: async (eatchBatchPayload: EachBatchPayload) => {
const { topic, partition, batch } = eachBatchPayload
eachBatch: async (eachBatchPayload: EachBatchPayload) => {
const { batch } = eachBatchPayload
for (const message of batch.messages) {
const prefix = `${topic}[${partition} | ${message.offset}] / ${message.timestamp}`
const prefix = `${batch.topic}[${batch.partition} | ${message.offset}] / ${message.timestamp}`
console.log(`- ${prefix} ${message.key}#${message.value}`)
}
}
Expand Down

0 comments on commit b7bb7db

Please sign in to comment.